![]() * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com> |
||
---|---|---|
.. | ||
Source | ||
proj.android | ||
proj.ios | ||
proj.linux | ||
proj.mac | ||
proj.wasm | ||
proj.win32 | ||
proj.winrt | ||
CMakeLists.txt | ||
README.md |
README.md
unit-tests
Description
unit-tests
app is a console application that runs Axmol's automated unit tests. It can be used for
test driven development, checking for regressions during development, or running tests in a CI/CD
pipeline.
One of the unit-tests
goals is for it to be fast, so it can be run frequently during development.
Setup
The unit-tests
app is a console app. For writting tests unit-tests
uses
doctest library. It's pretty simple and easy to use.
Usage
Supported platforms:
- Linux
- macOS
- Windows
To run tests simply build the unit-tests
app and run it. It will run all tests automatically and
print the results to the console. The app also returns error code 0 if all tests pass and non 0
code if any test fails.
Use axmol build -d tests/unit-tests
for building the unit-tests
app. Then use command line to
run the app. You can also run it with unit-tests --help
to see all available options.
Writing tests
Adding new tests
Let's say you want to write unit tests for ax::Node
class. To add a new test follow these steps:
-
Find or create a source file to hold your tests. For easier navigation test source files follow the same layout and naming as the engine source files, and only add a
Tests
postfix. For exampleax::Node
in engine is incore/2d/Node.h
, so the test file should be intests/unit-tests/Source/core/2d/NodeTests.cpp
. -
If the file doesn't exist, then create a new file, in this case
tests/unit-tests/Source/core/2d/NodeTests.cpp
. -
Register new file in
tests/unit-tests/CMakeLists.txt
. -
For the test file use the following structure:
// <add copyright message here> #include <doctest.h> #include "2d/Node.h" // Include the thing you're testing USING_NS_AX; // For suite name use the part of the source file path, in this case `2d` followed by the // class name you will be testing, in this case `Node`. Separate the parts with a slash. TEST_SUITE("2d/Node") { }
-
If you will be testing functions, methods or their groups, then use their names in the test case like this:
TEST_SUITE("2d/Node") { TEST_CASE("addChild") { // addChild() tests go here } TEST_CASE("removeFromParent") { // removeFromParent() tests go here } }
-
If you will be testing some specific functionality, then name what you're testing like this:
TEST_SUITE("2d/Node") { TEST_CASE("adding_child_clears_dirty_flag") { // Test goes here } }
-
TestUtils.h
header contains some helpers for testing. -
For reference example see
FileUtils
tests intests\unit-tests\Source\core\platform\FileUtilsTests.cpp
.
Writing tests
For more information on how to write tests using doctest
, see the
doctest documentation
Things to keep in mind
- For suite, case or subcase names use only
a-zA-Z0-9_/[]
symbols for easier use in command line. - Try to follow the established naming and structure for suites and cases. This is for easier filtering when running tests.