Skip to content

Testing

Kpaubert edited this page Feb 20, 2021 · 11 revisions

This page contains information on how to run tests, and where tests are located. For more information about the folder structure checkout the folder structure page

How to run tests

Run the test suite with

dotnet test

Where to find tests

All tests are located in /BackendTests/.

Testing framework

This project uses NUnit, a unit-testing framework for all .Net languages. NUnits own documentation is available on their documentation page.

Coverage and purpose

  • What does the backend testing cover?

  • In short: What is our purpose of doing testing?

This projects sees to serve as a man-in-the middle between Open Data sources and end-users. It is therefore critical that data being processed and displayed are correct in value and type. Writing tests is on way of assuring that these properties are maintained at entry, during processing and at exit.

Mocking

When testing, we can either access the relevant API's with regular HTTP requests, or use fake data (mocking). We use a mocking tool called "Bogus" to create this fake data.

The application decides whether or not to use real data during runtime, by checking a configuration variable called "MockRequests". This check can be found in the Startup.cs file, and looks like this:

Configuration.GetValue<bool>("MockRequests")

The correct services are then applied to the application, and it runs with either real or mocked data.

Configuring a new mocking service

To create a new mocking service, the easiest way is to look at the Met API example, located in the Mocks directory in the project root. You will need a POCO so you can configure the mock-object. It's naturally better if you know approximately what values to use (we want the mocking data to be as accurate as possible). Start by looking at the existing example(s), or check out this resource.