TheBasics - VianneyDoleans/Teia-Tests-Documentation GitHub Wiki

The basics

This section is regrouping the minimum of knowledge you need to know to start Teia project testing.
More details/explanations are given in the next sections.

Dependency injection

First, you have to know and understand Autofac.
Autofac is used for the depedency injections of Teia : constructors' arguments are injected instead of be declared on the method's call.
For testing the services, modules etc, you will have to create theses objects in a testing environment by using constructors and so redeclare the dependency injections.

  • C# Dependency Injection with Autofac (video)
    • This vidoo is really good because the narrator doesn't just give instructions, it explains how its works, why you have to do this, etc.

Note : Testing environment is a sandbox. At the beginning, there is nothing inside, you will have to declare and create what you need. So for each dependency needed for the object you're creating, you will have to declare the dependencies of this dependency (it gives a tree of dependencies).

Tests

Nunit

Nunit is an open-source testing framework used in C#/.NET environment.
Nunit was used by Orchard developers for orchard CMS developpment (started in 2011 and discontinued in 2019).
Current Teia solution is based on Orchard CMS, and so, used Nunit Framework.
There is many other frameworks for this purpose (MSTest, Xunit, ...).

  • Although an important part of the current .NET community will prefer Xunit for the modern take in unit testing, Nunit keeps a solid and well proven status.

Documentation

To understand unit test operation, I recommend you to read theses articles :

Mock

Okay so now you know how to make a unit test and how autofac works. The next step is to understand mock processes.

What is a mock ?

To understand the concept of Mock, I recommend you to read theses articles :

To complement the comprehension, these brief explanations resume the subject :

How to use Moq ?

In Teia solution, we are using Moq framework to realize your mocks.

AutoFixture

Autofixture enables to automatically pre-populate your class, interfaces and data-types with test-data.
Autofixture in Teia's tests is used as a complement of Moq Framework (see previously) to realize our mocks.

What is AutoFixture ? How to use it ?