Skip to content

giuliastefani/WeatherForecast

 
 

Repository files navigation

Weather Forecast Api

This repository have the pourpose of training my team in building effective tests and pass through some issues we find during the development, such as mapping errors, dependency injection, logical error, test implementation not following business and more.

Basically the application consists of consumming the MetaWeather API to get the weather by location and convert the results for the desired thermometric scale.

The tests are distributed in three layers of the bottom of the original test pyramid drawn by Martin Fowler. Follow the links for more information.

3 layers test pyramid with Functional tests at the top, followed by integration tests and unit tests on bottom

Usage

There are two branches in this repository for training, the main objective of both are to get to the maximum code coverage and mutant killed you can get.

The Broken branch have some tests already implemented, with tests passing, breaking and missing. Use this to also improve your debugging skills.

The Missing branch doesn't have any tests implemented, use your creativity and write them in your own code style and techniques.

Running the application

Run command inside the api project folder:

$ dotnet run

Running the tests

Run command on the root folder or inside a test project folder:

$ dotnet test

Running the code coverage analysis

If you don't have reportgenerator tool installed, go to the root of the project and run:

$ dotnet tool restore

On the root folder run the following commands:

$ dotnet test WeatherForecast.sln /p:CoverletOutputFormat=opencover /p:CoverletOutput=./TestResults/ /p:CollectCoverage=true

$ dotnet reportgenerator "-reports:./tests/WeatherForecast.UnitTest/TestResults/coverage.opencover.xml;./tests/WeatherForecast.IntegrationTest/TestResults/coverage.opencover.xml;./tests/WeatherForecast.FunctionalTest/TestResults/coverage.opencover.xml" "-targetdir:coveragereport" -reporttypes:Html

Running the mutation tests

If you don't have dotnet-stryker installed, go to the root of the project and run:

$ dotnet tool restore

On WeatherForecast/tests/WeatherForecast.UnitTest run:

$ dotnet stryker --project-file=[projectfile]

Built with

  • .NET Core 3.1 - Software Developmet Kit (SDK)
  • xUnit.net - Unit Test Framework
  • Fluent Assertions - Unit Test Assertions Extension Methods
  • Moq - The most popular mocking library for .NET
  • WireMock - A flexible library for stubbing and mocking web HTTP responses

My results

Test pyramid

Test pyramid result with 2 functional tests, 5 integration tests and 23 unit tests

Coverage

Coverage result with 100% coverage on core project and 93% coverage on api project

Mutation report of the controllers

Mutation report with 100% killed mutations on controllers

Mutation report of the core logic

Mutation report with 100% killed mutations on core logic

Mutation report of the services

Mutation report with 100% killed mutations on services

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%