目录

Unit testing at AzerothCore

How to compile and run the AC unit tests

  1. You have to compile your core by passing -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
  1. You can now run the unit tests using:
./build/src/test/unit_tests

How to write unit tests for AzerothCore

Googletest Framework

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.

File structure

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

Singleton issues

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:

Existing unit tests examples in AzerothCore

Run tests in IDEs

You can also run the tests directly in IDEs such as CLion

CLion lets you easily run the tests with debug and with coverage:

AzerothCore running tests with CLion

then it shows which lines of the code are covered by the tests (green lines) and which ones are still uncovered (red lines):

AzerothCore test coverage CLion

Happy testing!