| ... | ... | @@ -2,7 +2,7 @@ |
|
|
|
|
|
|
|
Unit-tests are an **ESSENTIAL** part of any codebase to assert the behaviour of a new feature and the consequences of any modification in the codebase. Any piece of production code that is not covered by a unit-test will probably later lead to a longer debug session or worse: undetected bad/undefined behaviours.
|
|
|
|
|
|
|
|
## Structure of tests
|
|
|
|
## Structure of unit_test folder
|
|
|
|
|
|
|
|
Each Aidge module can be supplemented by a test directory called ``unit_tests`` with the following hierarchy:
|
|
|
|
|
| ... | ... | @@ -19,7 +19,7 @@ unit_tests/ |
|
|
|
|
|
|
|
An example of `CMakeLists.txt` file can be found in aidge_core module [here](https://gitlab.eclipse.org/eclipse/aidge/aidge_core/-/blob/main/unit_tests/CMakeLists.txt?ref_type=heads)
|
|
|
|
|
|
|
|
## Writing a test file
|
|
|
|
## How to write a test
|
|
|
|
|
|
|
|
Aidge unit-tests are performed with the C++ test framework [Catch2](https://github.com/catchorg/Catch2).
|
|
|
|
|
| ... | ... | @@ -41,7 +41,13 @@ TEST_CASE("test_title", "[tag1][tag2]...[tagN]") { |
|
|
|
```
|
|
|
|
|
|
|
|
There can be any number of TEST_CASE and SECTION as you want. `[tag1][tag2]...[tagN]` are tag declaration for individual tests calls that we'll see later.
|
|
|
|
### About test sections
|
|
|
|
Each `SECTION` of a test case will be executed in standalone, meaning that that program will start from the beginning of the `TEST_CASE`(and if the `SECTION` is nested, go through each parent `SECTION`).
|
|
|
|
|
|
|
|
This allows for 2 things :
|
|
|
|
1. Factorize all the common setup & teardown required for tests.
|
|
|
|
2. Creating scenarios for your `TEST_CASE` and test each one separately.
|
|
|
|
### Create assertions
|
|
|
|
You can add assertions in your tests that should fail and stop the execution (or not) if the program behaviour is not as expected. You can find every assertions available on the official Catch2 [documentation](https://github.com/catchorg/Catch2/blob/devel/docs/tutorial.md). Here are some examples:
|
|
|
|
- `REQUIRE(<true_false_statement>)`
|
|
|
|
- `REQUIRE_THROWS(...)`
|
| ... | ... | |