tfsantosbr / dotnet-sample-api

Cobertura de código nos testes de uma aplicação .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.NET Complete Sample API

Cobertura de código nos testes de uma aplicação .NET

Implementações

  • CQRS Pattern
  • Notification Pattern
  • Testes unitários
  • Testes de Integração
  • Cobertura de Testes
  • Testes de Carga
  • Docker
  • CI/CD com Github Actions
  • Code Quality com Sonaqube

Referências

Testes Unitários

Executando os testes unitários:

dotnet test ./tests/SampleApp.Tests --verbosity minimal --logger:"html;LogFileName=tests-results.html" --collect:"XPlat Code Coverage"

Migrations

You will need .NET EF Tools to run this commands

# add migration
dotnet ef migrations add <MIGRATION_NAME> -p src/SampleApp.Infra/ -c SampleAppContext -s src/SampleApp.Api -o Contexts/Migrations

# remove migration
dotnet ef migrations remove -p src/SampleApp.Infra/ -c SampleAppContext -s src/SampleApp.Api

# update database
dotnet ef database update -p src/SampleApp.Infra -c SampleAppContext -s src/SampleApp.Api

# generate scripts for manual database update
dotnet ef migrations script -p src/SampleApp.Infra/ -c SampleAppContext -s src/SampleApp.Api -o ./scripts/migrations.sql

Cobertura de Testes

Instalando a ferramenta de geração de relatório globalmente:

dotnet tool install --global dotnet-reportgenerator-globaltool

Gerando o relatório:

cd ./tests/SampleApp.Tests/TestResults
cd $(ls -d */|head -n 1)
reportgenerator "-reports:coverage.cobertura.xml" "-targetdir:coveragereport" -reporttypes:Html

Testes Integrados

Instalando a ferramenta newman para gerar os testes integrados:

npm install -g newman

Executando os testes integrados

newman run tests/SampleApp.Integration.Tests/integration-tests.json -e tests/SampleApp.Integration.Tests/environments/docker.environment.json --insecure

Qualidade de Código

dotnet tool install --global dotnet-sonarscanner
dotnet tool install --global dotnet-coverage
dotnet sonarscanner begin -o:tfsantosbr -k:tfsantosbr_dotnet-sample-api -d:sonar.host.url=https://sonarcloud.io -d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
dotnet build --no-incremental
dotnet-coverage collect 'dotnet test' -f xml  -o 'coverage.xml'
dotnet sonarscanner end

Testes de Carga

Instalando a ferramenta de testes de Carga K6:

Executando os Testes de Carga:

k6 run -e HOSTNAME=https://localhost:5001 tests/SampleApp.Load.Tests/script.js

About

Cobertura de código nos testes de uma aplicação .NET


Languages

Language:C# 94.2%Language:JavaScript 3.5%Language:Dockerfile 2.3%