Skip to content

Latest commit

 

History

History
124 lines (85 loc) · 4.01 KB

run-tests-locally.md

File metadata and controls

124 lines (85 loc) · 4.01 KB

Run tests locally

Use this documentation to run tests locally.

Unit tests

All .NET code is unit tested where possible (as per the test approach).

You can run unit tests using your preferred IDE, or open a terminal in the project directory and run:

dotnet test

Note

The FIAT db tests will fail unless the Docker engine is running - see ADR 15. Use Test Containers to unit test FIAT database configuration, usages and change tracking on why and how this works.

Analyse test coverage

This project uses a mutation score to analyse effective test coverage when opening up a new pull request. Stryker.Net is included in our dotnet-tools manifest for checking mutation score locally.

Open a terminal at the root folder and type the following to run and open a Stryker report:

# Install stryker and other tools (only need to do this after a version update)
dotnet tool restore

# Analyse all unit tests and open a html report afterwards
dotnet stryker -o --concurrency 6 

# Only mutate one file
dotnet stryker -o --project "DfE.FindInformationAcademiesTrusts.csproj" --mutate "**/TrustService.cs" --concurrency 6

You will be able to find all reports in the StrykerOutput folder in your project root.

UI tests

Installation

  1. Open a terminal in your repository and run:

    # go to the cypress tests folder
    cd tests/DFE.FindInformationAcademiesTrusts.CypressTests
    
    # install dependencies
    npm install    
    
    # set up Cypress
    npx cypress open    #This will run Cypress for the first time and notify you of such, it should then setup Cypress locally for you.
  2. Create a file in tests/DFE.FindInformationAcademiesTrusts.CypressTests called cypress.env.json which contains the following:

    {
      "URL": "<url of the application under test>",
      "AUTH_KEY": "<auth bypass secret for application>"
    }

Running UI tests

To run against a deployed environment

  1. Make sure your cypress.env.json file contains the correct information for the environment you want to use.

  2. Open a terminal in your repository and run:

    # go to the cypress tests folder
    cd tests/DFE.FindInformationAcademiesTrusts.CypressTests
    
    # run tests 
    npx cypress open
  3. You should now see the Cypress UI open

    • click the e2e test option
    • click the browser you want to test in
  4. You should now see your test specs - to run these you click on the test spec and it should then run all the tests within said spec.

    • If the test passes you should see a green tick next to said test with confirmation that all tests within the spec are passing if multiple.
    • If the test fails it should show you within the runner what the failed test step is with a screenshot of where it failed to help you in debugging the fail. (N.b Cypress will rerun the open spec everytime you save one of your open files)

To run against your local branch

  1. Start the application in Docker

  2. Set the TestOverride__CypressTestSecret value in docker/.env to any value that you like

  3. Update your cypress.env.json to:

    {
      "URL": "http://localhost",
      "AUTH_KEY": "<the TestOverride__CypressTestSecret value you set in step 2>"
    }
  4. Open a terminal in your repository and run:

    # go to the cypress tests folder
    cd tests/DFE.FindInformationAcademiesTrusts.CypressTests
    
    # run tests 
    npx cypress open