Accelergreat.Web
3.0.0-beta.1
Prefix Reserved
See the version list below for details.
dotnet add package Accelergreat.Web --version 3.0.0-beta.1
NuGet\Install-Package Accelergreat.Web -Version 3.0.0-beta.1
<PackageReference Include="Accelergreat.Web" Version="3.0.0-beta.1" />
paket add Accelergreat.Web --version 3.0.0-beta.1
#r "nuget: Accelergreat.Web, 3.0.0-beta.1"
// Install Accelergreat.Web as a Cake Addin #addin nuget:?package=Accelergreat.Web&version=3.0.0-beta.1&prerelease // Install Accelergreat.Web as a Cake Tool #tool nuget:?package=Accelergreat.Web&version=3.0.0-beta.1&prerelease
uid: DeveloperDocumentation.Index
Ultra Fast Integration Tests
Accelergreat your tests.
Write and execute efficient and high-performance integration tests with ease using Accelergreat. It is a powerful .NET integration testing solution that automatically provisions and manages external dependencies for your tests, such as databases and APIs. Simplify your integration testing development process today with Accelergreat.
Overview
Accelergreat is a new and innovative testing platform designed to make integration testing easier.
Integration tests are essential to ensuring your code works and stays working. However, they have been challenging to write and run quickly in the past, earning a reputation as a problem area in the development world.
With Accelergreat we intend to make this a problem of the past by doing all the hard work for you.
Accelergreat currently supports xUnit and plans to support other test runners in the future.
Quality
We take pride in writing clean, quality code and use SonarCloud to scan our code for quality and security issues. This adds an extra layer of assurance that the code we ship is safe for your codebase to consume.
Version
Accelergreat follows Semantic Versioning 2.0.0 for releases.
Packages
Accelergreat
Accelergreat.EntityFramework
Accelergreat.EntityFramework.InMemory
Accelergreat.EntityFramework.PostgreSql
Accelergreat.EntityFramework.Sqlite
Accelergreat.EntityFramework.SqlServer
Accelergreat.Web
Accelergreat.Xunit
Download
You can download Accelergreat packages from NuGet.org.
Configuration
Accelergreat supports the overriding of configuration for managed external dependencies such as databases.
Accelergreat will read the following files in the root level of your test projects that have the CopyToOutputDirectory
setting set to Always
or PreserveNewest
:
accelergreat.json
accelergreat.{environment}.json
accelergreat.{environment}.json
is supported to allow you to have different configurations for your local machine and CI pipeline.
{environment}
is defined by setting an environment variable called ACCELERGREAT_ENVIRONMENT
.
A schema has been provided for the configuration files. An example is shown below:
{
"$schema": "https://cdn.accelergreat.net/configuration/3.0.0-beta.1/schema.json#"
}
Getting started
Components
To further understand components beyond what the below getting started guide shows, read about all the different components Accelergreat offers and to understand how to build your own components. Please follow this guide.
Example use case
Accelergreat has been designed with modularity and flexibility in mind. Whilst the example we have provided below may not match your specific use case, this example was chosen to best show the capabilities of Accelergreat. It should be an effective reference point for your own implementations.
To see other examples, you can look on our GitHub examples repo.
Database (Entity Framework SQL Server) + Web API integration test
Process
- Install the required packages
- Create the Accelergreat Components
- Database component class(es)
- Web Api component class(es)
- Create an Accelergreat
Startup
class - Write your first Accelegreat Integration Test
Install the required packages
Accelergreat.EntityFramework.SqlServer
Accelergreat.Web
Accelergreat.Xunit
Create the Accelergreat Components
One of the core features of Accelergreat is the concept of components. A component represents a dependency for your tests. For example a database or a web API.
To further understand components beyond what this getting started guide shows, read about all the different components Accelergreat offers and to understand how to build your own components. Please follow this guide.
In our example we only need two components. One for our SQL Server database, and one for our Web API.
Database component
Create a class that inherits from SqlServerEntityFrameworkDatabaseComponent
.
If you need to override any of the configuration values, see SqlServerEntityFrameworkConfiguration
for the defaults.
using Accelergreat.EntityFramework.SqlServer;
using Microsoft.Extensions.Configuration;
namespace ExampleTestProject.Components;
public class ExampleDatabaseComponent : SqlServerEntityFrameworkDatabaseComponent<ExampleDbContext>
{
public ExampleDatabaseComponent(IConfiguration configuration) : base(configuration)
{
}
}
Web API component
To interact with a .NET Web API in our integration tests, we need to create a Web App Component. (If you need to create a Microservice Architecture then follow this guide
Web app components run an instance of the API defined by the Web API startup class passed into the generic type parameter. The following steps will set up a component for you:
- Create a class derived from
WebAppComponent
. - Inject the database connection string(s).
- [Optional] overriding appsettings.
Create the class derived from WebAppComponent
To create a Web App Component, create a class that inherits from WebAppComponent
and pass in your Web API startup class as the generic type parameter.
Using a Startup class
using System.Collections.Generic;
using Accelergreat.Web;
using Accelergreat.Web.Extensions;
using Microsoft.Extensions.Configuration;
namespace ExampleTestProject.Components;
public class ExampleApiComponent : WebAppComponent<ExampleApi.Startup>
{
protected override void BuildConfiguration(
IConfigurationBuilder configurationBuilder,
IReadOnlyAccelergreatEnvironmentPipelineData accelergreatEnvironmentPipelineData)
{
configurationBuilder.AddEntityFrameworkDatabaseConnectionString<ExampleDbContext>(
"ExampleConnectionStringName", accelergreatEnvironmentPipelineData);
}
}
Using a Program class (minimal APIs)
With the recent introduction of minimal apis in Aspnet core, you can now configure your application entirely in Program.cs . The Progam class is now in the global
App Domain as an internal class of the Api assembly. If you are using miniminal apis then you will have to expose InternalsVisibleTo
to the Test Assembly by editing the csproj file of the Api project:
<Project Sdk="Microsoft.NET.Sdk.Web">
...
<ItemGroup>
<InternalsVisibleTo Include="ExampleTestProject" />
</ItemGroup>
...
using System;
using System.Collections.Generic;
using Accelergreat.EntityFramework.Extensions;
using Accelergreat.Environments;
using Accelergreat.Web;
using GuestAndActivities.Data.Contexts;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
namespace ExampleTestProject.Components;
internal class ExampleApiComponent : WebAppComponent<Program>
{
protected override void BuildConfiguration(
IConfigurationBuilder configurationBuilder,
IReadOnlyAccelergreatEnvironmentPipelineData accelergreatEnvironmentPipelineData)
{
configurationBuilder.AddEntityFrameworkDatabaseConnectionString<ExampleDbContext>(
"ExampleConnectionStringName", accelergreatEnvironmentPipelineData);
}
}
Inject the database connection string(s)
In the examples above, we need to provide the database connection string to the Web API configuration a database connection string. We do this by overriding > BuildConfiguration
and calling configurationBuilder.AddEntityFrameworkDatabaseConnectionString
.
Create a Startup
class
To create a working Accelergreat Start up class, follow these three important steps:
Create the class
Create a Startup
class in your test project that implements IAccelergreatStartup
.
Add the Assembly Attribute**
Accelergreat extends the xunit test framework, we have provided an assembly attribute that will instruct xunit to use the Accelergreat extended xunit test framework.
Important
In the Startup
file, add assembly attribute UseAccelergreatXunitTestFramework
. Without this, the Startup
code will not be executed.
Registering components in their dependent order (least dependent last)**
Lastly we need to register our components. In the ConfigureServices
implementation, call services.AddAccelergreatComponent
for each component as the type parameter.
Important The order in which components are initialized is defined by the order they are registered.
In our example, we need to initialize the database before the web API so that it can access the database connection string.
using Accelergreat.Xunit;
using Accelergreat.Xunit.Attributes;
using ExampleTestProject.Components;
using Microsoft.Extensions.DependencyInjection;
[assembly: UseAccelergreatXunitTestFramework]
namespace ExampleTestProject;
public class Startup : IAccelergreatStartup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddAccelergreatComponent<ExampleDatabaseComponent>();
services.AddAccelergreatComponent<ExampleApiComponent>();
}
}
Write your first Accelegreat Integration Test
Now that we've got everything set up, we're going to write our first test.
For this example, we'll also be using FluentAssertions to keep our assertion code clean and easy to read. We'll also follow the Arrange Act Assert (AAA) pattern:
Arrange Set up and insert our test data
Act Call the API endpoint
Assert Validate that the response data is correct
Create a test that that inherits from AccelergreatXunitTest
.
using System.Threading.Tasks;
using Accelergreat.Environments.Pooling;
using Accelergreat.Xunit;
using ExampleTestProject.Components;
using FluentAssertions;
using Newtonsoft.Json;
using Xunit;
namespace ExampleTestProject.Tests;
public class ExampleTests : AccelergreatXunitTest
{
public ExampleTests(IAccelergreatEnvironmentPool environmentPool) : base(environmentPool)
{
}
[Fact]
public async Task Examples_GetById_ReturnsCorrectExample()
{
// Arrange
var exampleEntity = new ExampleEntity();
var dbContextFactory = GetComponent<ExampleDatabaseComponent>().DbContextFactory;
await using (var context = dbContextFactory.NewDbContext())
{
context.Set<ExampleEntity>().Add(exampleEntity);
await context.SaveChangesAsync();
}
var httpClient = GetComponent<ExampleApiComponent>().CreateClient();
// Act
var httpResponseMessage = await httpClient.GetAsync($"examples/{exampleEntity.Id}");
// Assert
httpResponseMessage.IsSuccessStatusCode.Should().BeTrue();
var body = await httpResponseMessage.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<ExampleEntity>(body)!;
result.Id.Should().Be(exampleEntity.Id);
}
}
Parallel execution (Premium feature)
One of the best features of Accelergreat is the ability to have your integration tests run in parallel, gaining massive performance improvements on multi-threaded machines.
It's as easy as config change. In your accelergreat configuration, make sure to add your client id and client secret:
{
"$schema": "https://cdn.accelergreat.net/configuration/3.0.0-beta.1/schema.json#",
"License": {
"ClientId": "YourClientId",
"ClientSecret": "YourClientSecret"
}
}
Given credentials are provided and authentication is successful, Accelergreat will automatically execute in parallel when the following criteria is met:
- More than 1 test collection is queued for execution.
parallelizeTestCollections
has not been set to false in yourxunit.runner.json
.maxParallelThreads
has not been set to 1 in yourxunit.runner.json
.
By default, Accelergreat uses the max threads allowed from the number of logical processors on the machine. You can override this by setting the maxParallelThreads
property in your xunit.runner.json
configuration file.
Debugging in Visual Studio
Important When debugging tests in Visual Studio, do not click the stop button. Even if an exception occurs, click continue and let the test run through. If you click the stop button xunit will not run cleanup operations and dependencies will not be disposed of. This is especially important when debugging tests that use database dependencies.
Supported integrations
Entity Framework
- In-Memory
- Sqlite
- SQL Server
- PostgreSql
Application
- .NET Web API: dotnet6+
Upcoming integrations
Entity Framework
- MySql
- CosmosDB
Application
- Azure Functions
- AWS Lambda
Questions & Feedback
Please email mail@accelergreat.net for any questions or feedback you may have.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Accelergreat (>= 3.0.0-beta.1)
- Microsoft.AspNetCore.Mvc.Testing (>= 6.0.0)
- Microsoft.AspNetCore.TestHost (>= 6.0.0)
- Microsoft.Extensions.Configuration (>= 6.0.0)
-
net7.0
- Accelergreat (>= 3.0.0-beta.1)
- Microsoft.AspNetCore.Mvc.Testing (>= 7.0.0)
- Microsoft.AspNetCore.TestHost (>= 7.0.0)
- Microsoft.Extensions.Configuration (>= 7.0.0)
-
net8.0
- Accelergreat (>= 3.0.0-beta.1)
- Microsoft.AspNetCore.Mvc.Testing (>= 8.0.0)
- Microsoft.AspNetCore.TestHost (>= 8.0.0)
- Microsoft.Extensions.Configuration (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.1.1-beta | 82 | 11/6/2024 |
3.1.0-beta | 36 | 11/6/2024 |
3.0.0 | 123 | 7/13/2024 |
3.0.0-beta.2 | 125 | 2/12/2024 |
3.0.0-beta.1 | 63 | 2/9/2024 |
2.3.0-beta | 348 | 1/23/2024 |
2.2.7 | 372 | 9/1/2023 |
2.2.6-beta | 137 | 9/1/2023 |
2.2.5-beta | 150 | 9/1/2023 |
2.2.4 | 170 | 9/1/2023 |
2.2.3-beta | 303 | 3/26/2023 |
2.2.2-beta | 172 | 3/26/2023 |
2.2.1-beta | 186 | 3/25/2023 |
2.2.0-beta | 176 | 3/25/2023 |
2.1.0-beta | 190 | 3/24/2023 |
2.0.0 | 692 | 3/8/2023 |
2.0.0-beta02 | 168 | 3/1/2023 |
2.0.0-beta01 | 185 | 2/1/2023 |
1.7.2-beta | 189 | 10/21/2022 |
1.7.1 | 1,162 | 10/18/2022 |
1.7.0 | 442 | 10/18/2022 |
1.7.0-beta | 171 | 8/28/2022 |
1.6.4 | 540 | 8/27/2022 |
1.6.3-beta | 1,011 | 8/14/2022 |
1.6.1-beta | 248 | 8/12/2022 |
1.6.0-beta | 223 | 7/18/2022 |
1.5.6-beta | 308 | 7/4/2022 |
1.5.4-beta | 316 | 6/25/2022 |
1.5.3-beta | 194 | 6/24/2022 |
1.5.2-beta | 212 | 6/23/2022 |
1.5.1-beta | 195 | 6/20/2022 |
1.5.0-beta | 176 | 6/20/2022 |
1.4.6 | 540 | 6/8/2022 |
1.4.5-beta | 204 | 5/30/2022 |
1.4.4-beta | 195 | 4/24/2022 |
1.4.3-beta | 190 | 4/23/2022 |
1.4.2 | 510 | 3/15/2022 |
1.4.1-beta | 239 | 3/2/2022 |
1.4.0-beta | 194 | 2/17/2022 |
1.3.6 | 495 | 1/30/2022 |
1.3.5 | 468 | 1/30/2022 |
1.3.2-beta | 216 | 1/27/2022 |
1.3.1-alpha | 209 | 1/25/2022 |
1.3.0-alpha | 220 | 1/25/2022 |
1.2.0 | 475 | 1/23/2022 |