This is a exmaple solution for TDD training. A C# port of this sea-tdd-workshop-09-2021
Project | Description |
---|---|
LoanNaja.Core | Business logic and infrastucture |
LoanNaja | Web |
LoanNaja.Core.Test | Test for business logic |
LoanNaja.Test | Test for controller using mock |
LoanNaja.IntegrationTest | Integration Test using WebApplicationFactory |
LoanNaja.Spec | Black box test |
LoanNaja.ContractTest | Contact test |
-
Add a coverlet to your test project
dotnet add package coverlet.msbuild
-
Check for code coverage percentage
dotnet test /p:CollectCoverage=true
-
Add a mock for a parent class
Mock<IDerived> mock = new Mock<IDerived>( MockBehavior.Strict ); mock.Setup( obj => obj.Value ).Returns( "Derived" ); mock.As<IBase>().Setup( obj => obj.Value ).Returns( "Base" );
-
Format your C# code using csharpier
dotnet-csharpier
-
Run a server for acceptance tests
docker build -t loan-naja -f ./src/LoanNaja/Dockerfile . docker run -d --name loannaja -p 8080:80 loan-naja:latest
-
See server logs
docker logs loannaja
-
Close a server
docker stop loannaja docker rm loannaja
-
Check access to your server
curl http://docker.local:8080
-
Run test except an acceptance test
dotnet test --filter "Category!=Spec"
-
Run acceptance tests
docker-compose up --exit-code-from acceptancetests
docker-compose up --exit-code-from acceptancetests --build docker-compose up --exit-code-from acceptancetests --no-cache
Go check Setup