- ETJump uses Google Test framework for unit testing.
- Some newer parts of the mod have unit tests.
- New features ideally should have unit tests as well, this guarantees code quality.
- Basic guide on how to use googletest is here.
ctest is a built-in CMake feature, that allows easy test definition and execution.
The usage is pretty simple as follows:
- Run
ctestwithin thebuilddirectory.- For
slnbased project, usectest -C Releaseorctest -C Debug.
- For
You can provide options to ctest to perform specific actions:
ctest --output-on-failureprints verbose information on failed tests.ctest -j 4runs tests in parallel to provide significant speed-up.ctest --rerun-failedonly runs previously failed tests.ctest [-C Release] --rerun-failed --output-on-failurecombining all.- Use
ctest --helpto learn about other filtering options.
Alternatively, invoke googletest produced executable, this provides colored pretty print and own flags to perform filtering:
- Run
./tests/testsor.\tests\Release\tests.exe(for debug config useDebugdir). - Use
./tests/tests --helpor.\tests\Release\test.exe --helpto obtain usage information. - Use
./tests/tests --gtest_filter=InlineCommandParserTests.*to run only particular set of of tests. - Use
./tests/tests --gtest_filter=InlineCommandParserTests.Parse_HandlesSingleParamCorrectlyto run specific test.
Use Test Explorer from the Test menu, this gives better overview on discovered tests and provides a way to run only certain set of tests or debug failed tests.
Alternatively, in Solution Explorer (File list):
- Select
CMake/RUN_TESTSproject. - Open context menu and click on
Buildentry. - Examine the output on the subject of errors.
Use Test Explorer from the Test menu, this gives better overview on discovered tests and provides a way to run only certain set of tests or debug failed tests. It takes time to discover all tests.
TODO
To add new test:
- Create test in
testsdirectory. - You may use template as follows:
#include <gtest/gtest.h> // + your own header inclusion // define test suite name after your class name, // for instance CommandParsingTests class MyClassTests : public testing::Test { public: void SetUp() override { } void TearDown() override { } }; // define descriptive test name // for instance parseCommandString_ShouldNotFail TEST_F(MyClassTests, myMethodName_ShouldDoThis) { // set up the code ASSERT_TRUE(/* test codition */); } // add more tests
- You can check how other tests are done in ETJump to grasp the idea.
- Edit
tests/CMakeLists.txtfile.- Add to
add_executablefile list your own class. - Add to
add_executablefile list your own test file.
- Add to
- Upon invoking tests next time, cmake will automatically reconfigure itself to include your test suite.