Testing

Fanray uses xUnit and has both Unit Tests and Integration Tests to ensure code quality.

Overview

All tests are in the test solution folder. The unit tests use moq to mock up their dependencies, while the integration tests use SQLite in-memory mode as a relational database, without the overhead of actual database operations.

Convention

Currently for unit tests I use the name of the method I want to test followed by what I’m testing it for. For example

[Fact]
public async void GetActivePluginsAsync_returns_all_active_plugins_and_activates_any_new_plugins()
{
}

For integration tests I use more of a specification like method name that describes an action from the perspective of an end user. For example

[Fact]
public async void Admin_publishes_BlogPost_with_new_Category_and_Tag_from_OLW()
{
}

For the test implementation I interchange between the Arrange, Act and Assert or Given, When, Then.

Run Test In Parallel

I recommend Run Test In Parallel, in Visual Studio you can turn this option on the Test Explorer. This will run all the tests in parallel, xUnit has its way of specifing which tests are bundled to run together and you can google on that topic and take a further look. Basically this is not just for performance reason, also it ensures code stability as I have encoutnered issues that only show up when running tests in parallel.

Logging
Docs