Testing - KevinDHeath/NuGetPackages GitHub Wiki

Automated tests are a great way to ensure that the application code does what its authors intend.


A unit test is a test that exercises individual software components or methods, also known as a "unit of work." Unit tests should only test code within the developer's control. They do not test infrastructure concerns such as interacting with databases, file systems, and network resources.

Unit testing

Unit testing best practices
How to unit test Internal classes

A unit test helps write simpler, readable code and provides a means of verification for refactoring efforts. Test Driven Development (TDD) is when you write a unit test before the code it's meant to check. A unit test typically features three different phases: Arrange, Act, and Assert (sometimes referred to as AAA). For a unit test to be successful, the resulting behavior in all three phases must be in line with expectations.

Code coverage is a measurement of the amount of code that is run by unit tests - either lines, branches, or methods. The reports show the coverage metrics and also visualize which lines of the source code have been covered.

Code coverage reports

Use code coverage for unit testing

The code coverage feature in Visual Studio is only available with the Enterprise edition.

To install or update the ReportGenerator package as a global .NET tool use the following PowerShell commands:

dotnet tool list --global
dotnet tool install --global dotnet-reportgenerator-globaltool # default is the latest stable version
-or-
dotnet tool update --global dotnet-reportgenerator-globaltool  # update to the latest stable version

reportgenerator -help

Run the following commands from the Unit Test project directory.

  • To run the tests with no build and generate a HTML coverage report:
dotnet test --collect:"XPlat Code Coverage" --no-build --logger "html;logfilename=details.html"
reportgenerator -reports:TestResults\*\coverage.cobertura.xml -targetdir:TestResults\reports\html
  • To generate a coverage report with history:
    ⚠️ This will generate a new Coverage History file in the Testdata\history folder.
reportgenerator -reports:TestResults\*\coverage.cobertura.xml -targetdir:TestResults\reports\html -historydir:Testdata\history

Optional reportgenerator settings can be used.

  • To generate a coverage report with an increased Crap Score threshold:
    (v5.2.1: the default is 15)
reportgenerator -reports:TestResults\*\coverage.cobertura.xml -targetdir:TestResults\reports\html --riskHotspotsAnalysisThresholds:metricThresholdForCrapScore=26
  • To generate a coverage report with an increased Cyclomatic complexity threshold:
    (v5.2.0: the default is 30)
reportgenerator -reports:TestResults\*\coverage.cobertura.xml -targetdir:TestResults\reports\html --riskHotspotsAnalysisThresholds:metricThresholdForCyclomaticComplexity=36

An integration test differs from a unit test in that it exercises two or more software components' ability to function together, also known as their "integration." These tests operate on a broader spectrum of the system under test, whereas unit tests focus on individual components. Often, integration tests do include infrastructure concerns.

Integration testing

WPF Tutorials (GitHub)
WPF UI Workshops (GitHub)

There are 3 types of integration testing projects:

  • Controls - Custom controls for the user interface application.
  • MVVM - Core component to provide data and services for the user interface application.
  • WPF User Interface - used to test the functionality of the WPF packages.
    This is based on the Navigation MVVM tutorial by Singleton Sean and demonstrates how to combine navigation operations via the composite design pattern.

System testing are types of tests where a tester evaluates the whole system against the specified requirements.

End-to-end testing (also known as E2E testing) is a technique that verifies the functionality and performance of an entire software application from start to finish by simulating real-world user scenarios and replicating live data. Its objective is to identify bugs that arise when all components are integrated, ensuring that the application delivers the expected output as a unified entity.

Performance tests evaluate how a system performs under a particular workload. These tests help to measure the reliability, speed, scalability, and responsiveness of an application. For instance, a performance test can observe response times when executing a high number of requests, or determine how a system behaves with a significant amount of data. It can determine if an application meets performance requirements, locate bottlenecks, measure stability during peak traffic, and more.


⚠️ **GitHub.com Fallback** ⚠️