-
Notifications
You must be signed in to change notification settings - Fork 165
Unit tests
FreeSpace Open has a suite of unit tests that can be built by enabling the FSO_BUILD_TESTS
CMake variable. The unit tests are located in the test subdirectory and are implemented using Google Test. Every suit of tests is located in its own file and these files are grouped by the subsystem they belong to. If you are contributing code then you should write unit tests which make sure that the code actually works. These unit tests will also be run by our CI infrastructure which will make sure that the code isn't broken by another change at a later time.
If you want to add your own unit tests then you should take a look at the documentation of Google Test since that covers how to properly write unit tests using that framework. Additionally, there are a few classes which help writing unit tests for systems that are tightly integrated into the FSO code base. The FSTestFixture
provides a unit test fixture that allows to configure various options for how the environment should be set up when running the unit tests. By default it initializes a few subsystems that are always required and allows to optionally initialize subsystems that may be required by some tests. When you write your own tests then you should extend this class and provide the path to the test data you are going to use. This is typically the name of the subsystem you are currently testing.
In order to test the code we need some test data which causes a specific behavior. Since FSO supports mods by default that system is used to organize which test data is loaded for a specific test case. The test data is located in the test/test_data
folder in a standard source code checkout. The data in test_data
is automatically loaded for every test. Since you derived your test fixture from FSTestFixture
you can use pushModDir
for specifying which mod directory to use. Each mod directory is relative to the one that was active before the current one so you can organize your data hierarchically. Finally, each test case can have its own special test data. This test data must be located in a folder under the mod directory configured by the test fixture and it must be named like the unit test (make sure the case is the same or the tests will fail on Linux).