-DBUILD_TESTING=1
in your cmake
command.For example:
cd azerothcore mkdir build cd build cmake ../ -DWITH_WARNINGS=1 -DTOOLS=0 -DSCRIPTS=static -DBUILD_TESTING=1 make install -j 6
./build/src/test/unit_tests
We use googletest at AzerothCore as our testing framework. Some useful references that explain how it works are available at:
You can find plenty of other references online that explain how to deal with googletest or unit testing in general. If you know some other useful resources, feel free to edit this page and add them.
We recommend to read the googletest docs before starting to write unit tests.
Unit tests are located under src/test
. To add new tests, just edit the existing files or create new ones.
We try to follow the same structure of the src/*
directory, for example in order to test the file located at:
src/server/game/Miscellaneous/Formulas.h
We keep its test at:
src/test/server/game/Miscellaneous/FormulasTest.cpp
We have some legacy code in AzerothCore that is tightly coupled and there are singletons that are impossible to mock without some refactoring.
Following the gmock guidelines, to mock a class you should first define its interface. Then you can create mocks and use them when unit testing.
Examples of refactoring AzerothCore singletons to make them mockable (and improve the software architecture in general) are available:
You can also run the tests directly in IDEs such as CLion
CLion lets you easily run the tests with debug and with coverage:
then it shows which lines of the code are covered by the tests (green lines) and which ones are still uncovered (red lines):
Happy testing!