Skip to content
KlausEnevoldsen-Abtion edited this page Sep 26, 2023 · 2 revisions

Backend Test Projects

  • Api.Standalone.Tests: testing the minimal API of the Api.Standalone project with XUnit.
  • Api.WithReact.Tests: testing the API in the controller actions of the Api.WithReact project with XUnit.
  • DomainModel.Tests: testing the Domain Model project with XUnit.
  • EndToEnd.Tests: testing the Api.WithReact project with Playwright

Setup Playwright (for end-to-end tests)

To install Chromium for Playwright, start PowerShell as Administrator. (by right-clicking the PowerShell shortcut in the Start Menu and selecting "Run as Administrator".)

From the root folder of the Muffi.NET project, run the following PowerShell commands:

  • Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
  • cd tests\EndToEnd.Tests
  • .\bin\Debug\net7.0\playwright.ps1 install chromium

3. Run tests (including linting)

Backend

dotnet test

Frontend

yarn test

Test Naming Convention

EndToEnd Tests

For these tests we use the Gherkin syntax. Examples:

  • Given_SystemIsRunning_When_TheLandingPageIsCall_Then_ThePageIsShown
  • Given_UserExists_When_LoggingIn_Then_UserIsLoggedInAndRedirected
  • Given_UserDoesNotExist_When_LoggingIn_Then_UserIsNotLoggedIn
  • Given_UserExistsAndIsLoggedIn_When_LoggingOut_Then_UserIsLoggedOutAndRedirected

Unit Tests and Integration Tests

For these tests we use a shorter naming convention: MethodName_ExpectedBehavior_StateUnderTest. Examples:

  • LoadAll_ReturnTypeIsCorrect_WhenRequestIsValid
  • GetContactFormInformationIsCalled_ReturnsLoadContactFormResponse_WhenRequestIsValid
  • LoadJiraIssueDetails_ReturnsAnJiraIssueDetailsInstanceWithCorrectFields_WhenJiraIdentifierIsCorrect

Test Coverage

Backend code coverage requires Coverlet & ReportGenerator:

  • dotnet tool install -g dotnet-reportgenerator-globaltool
  • dotnet tool install -g coverlet.console

Backend report: (note slash/backslash use differs on different cmd shells)

  • dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=lcov ./tests/DomainModel.Tests
  • dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=lcov ./tests/Api.WithReact.Tests
  • reportgenerator "-reports:./tests/**/*.info" "-targetdir:coverage"

Frontend report:

  • yarn test --coverage

Clone this wiki locally