... | ... | @@ -19,6 +19,43 @@ Once you have created your source file, the first thing is to add the following |
|
|
```
|
|
|
The first 3 lines are needed in the case you want to run the test by itself, defining its own entrypoint. More on this in the next section.
|
|
|
Once you've added this 4 lines of code, you are ready to write your tests. Take a look at the examples in the Catch Github repo linked above, and at the examples in `src/tests/examples` in skyward-boardcore to know how to proceed.
|
|
|
|
|
|
### Order of execution
|
|
|
One thing that may not be clear is: how are test cases and sections executed by the Catch framework?
|
|
|
When you write a *TEST_CASE* with multiple sections inside it, the whole *TEST_CASE* "function" is executed **once for each section**. This means that all the code written outside sections is repeated for each section. Take a look at this example:
|
|
|
```cpp
|
|
|
TEST_CASE("Order of execution", "")
|
|
|
{
|
|
|
printf("Setup\n");
|
|
|
SECTION("S1")
|
|
|
{
|
|
|
printf("Executing the first section\n");
|
|
|
REQUIRE(true);
|
|
|
}
|
|
|
SECTION("S2")
|
|
|
{
|
|
|
printf("Executing the second section\n");
|
|
|
REQUIRE(true);
|
|
|
}
|
|
|
|
|
|
printf("Teardown\n");
|
|
|
}
|
|
|
```
|
|
|
The output will be:
|
|
|
```
|
|
|
Setup
|
|
|
Executing the first section
|
|
|
Teardown
|
|
|
Setup
|
|
|
Executing the second section
|
|
|
Teardown
|
|
|
```
|
|
|
|
|
|
This has a few consequences:
|
|
|
- You can create and *setup* objects writing the setup code in the test case, before each section. For example, you can create a state machine and bring it to a particular state you want to test.
|
|
|
- When a section starts executing, it will find the object exactly in the same state as you set it up. Changes to the object in previous sections are not reflected in other sections, because the object is effectively destroyed and recreated for each section.
|
|
|
- *Teardown* code can be written at the end of the test case. You can clear resources here, for example deleting a dinamically allocated object, in order not to leak memory each time a section is executed.
|
|
|
|
|
|
### Entrypoint configuration
|
|
|
To run the tests, you first need to define the entrypoint in `sbs.conf`. You will find two types of entrypoints for a test:
|
|
|
#### Standalone test
|
... | ... | |