text stringlengths 0 13.4k |
|---|
The GetIncompleteItemsAsync() method returns only the items |
owned by a particular user |
105 |
Integration testing |
Integration testing |
Compared to unit tests, integration tests are much larger in scope. |
exercise the whole application stack. Instead of isolating one class or |
method, integration tests ensure that all of the components of your |
application are working together properly: routing, controllers, services, |
database code, and so on. |
Integration tests are slower and more involved than unit tests, so it's |
common for a project to have lots of small unit tests but only a handful |
of integration tests. |
In order to test the whole stack (including controller routing), integration |
tests typically make HTTP calls to your application just like a web |
browser would. |
To write integration tests that make HTTP requests, you could manually |
start your application and tests at the same time, and write your tests to |
make requests to http://localhost:5000 . ASP.NET Core provides a |
nicer way to host your application for testing, however: the TestServer |
class. TestServer can host your application for the duration of the test, |
and then stop it automatically when the test is complete. |
Create a test project |
If you're currently in your project directory, cd up one level to the root |
AspNetCoreTodo directory. Use this command to scaffold a new test |
project: |
dotnet new xunit -o AspNetCoreTodo.IntegrationTests |
Your directory structure should now look like this: |
106 |
Integration testing |
AspNetCoreTodo/ |
AspNetCoreTodo/ |
AspNetCoreTodo.csproj |
Controllers/ |
(etc...) |
AspNetCoreTodo.UnitTests/ |
AspNetCoreTodo.UnitTests.csproj |
AspNetCoreTodo.IntegrationTests/ |
AspNetCoreTodo.IntegrationTests.csproj |
If you prefer, you can keep your unit tests and integration tests in |
the same project. For large projects, it's common to split them up |
so it's easy to run them separately. |
Since the test project will use the classes defined in your main project, |
you'll need to add a reference to the main project: |
dotnet add reference ../AspNetCoreTodo/AspNetCoreTodo.csproj |
You'll also need to add the Microsoft.AspNetCore.TestHost NuGet |
package: |
dotnet add package Microsoft.AspNetCore.TestHost |
Delete the UnitTest1.cs file that's created by dotnet new . You're ready |
to write an integration test. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.