155
CHAPTER 5 | Designing and Developing Multi-Container and Microservice-Based .NET Applications
Additional resources
•
Steve Smith. Testing controllers
(ASP.NET Core)
https://learn.microsoft.com/aspnet/core/mvc/controllers/testing
•
Steve Smith. Integration testing
(ASP.NET Core)
https://learn.microsoft.com/aspnet/core/test/integration-tests
•
Unit testing in .NET using dotnet test
https://learn.microsoft.com/dotnet/core/testing/unit-testing-with-dotnet-test
•
xUnit.net
. Official site.
https://xunit.net/
•
Unit Test Basics.
https://learn.microsoft.com/visualstudio/test/unit-test-basics
•
Moq
. GitHub repo.
https://github.com/moq/moq
•
NUnit
. Official site.
https://nunit.org/
Implementing service tests on a multi-container application
As
noted earlier, when you test multi-container applications, all the microservices need to be running
within the Docker host or container cluster. End-to-end service tests that include multiple operations
involving several microservices require you to deploy and start the whole application in
the Docker
host by running docker-compose up (or a comparable mechanism if you are using an orchestrator).
Once the whole application and all its services is running, you can execute end-to-end integration and
functional tests.
There are a few approaches you can use. In the docker-compose.yml file that you use to deploy the
application at the solution level you can expand the entry
point to use
dotnet test
. You can also use
another compose file that would run your tests in the image you are targeting. By using another
compose file for integration tests that includes your microservices
and databases on containers, you
can make sure that the related data is always reset to its original state before running the tests.
Once the compose application is up and running, you can take advantage of breakpoints and
exceptions if you are running Visual Studio. Or you can run the integration tests automatically in your
CI pipeline in Azure DevOps Services or any other CI/CD system that supports Docker containers.
Testing in eShopOnContainers
The reference application (eShopOnContainers) tests were recently restructured and now there are
four categories:
1.
Unit
tests, just
plain old regular unit tests, contained in the
{MicroserviceName}.UnitTests
projects
156
CHAPTER 5 | Designing and Developing Multi-Container and Microservice-Based .NET Applications
2.
Dostları ilə paylaş: