Skip to content

Add Doctest unit testing to C++ template project#3121

Merged
halx99 merged 4 commits intoaxmolengine:release/2.xfrom
theSlyest:doctest_unit_testing
Apr 23, 2026
Merged

Add Doctest unit testing to C++ template project#3121
halx99 merged 4 commits intoaxmolengine:release/2.xfrom
theSlyest:doctest_unit_testing

Conversation

@theSlyest
Copy link
Copy Markdown
Contributor

C++ Project Unit Testing

This PR integrates doctest (already part of the third-party dependencies) into the standard Axmol build system to enable seamless unit testing for C++ projects on desktop platforms.

Key changes include:

  • CMake Architecture: Added a new option _AX_TESTS (default: OFF) in CMakeLists.txt. When enabled, the build system generates a separate test executable alongside the main game binary.
  • Target Management: Configured set_target_properties to ensure the test executable is named ${APP_NAME}_test to prevent overwriting the game build.
  • Entry Point Adaptation: Modified AppDelegate and desktop-specific main.cpp files to conditionally invoke the doctest runner when the test flag is active.
  • Ensures that in "Test Mode," the engine initializes minimal requirements to run doctest suites instead of the main game loop.
  • Configuration: Updated internal CMake configuration files to handle the inclusion of doctest headers and definitions globally when _AX_TESTS is set.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a unit testing framework using doctest for the Axmol engine templates. It adds a new _AX_TESTS CMake option to enable a test target, modifies entry points across platforms (macOS, Linux, Windows) to run tests when enabled, and provides a sample test case. Feedback highlights a compilation error in the Windows entry point due to unnamed parameters, suggests using a generic bundle identifier for the test target on macOS, and recommends using a unique filename for the test batch script on Windows to avoid overwriting the main application's runner.

Comment thread templates/common/proj.win32/main.cpp
Comment thread templates/common/cmake/modules/AXGamePlatformSetup.cmake Outdated
Comment thread templates/common/cmake/modules/AXGamePlatformSetup.cmake Outdated
@theSlyest
Copy link
Copy Markdown
Contributor Author

Hi @halx99, is there something I need to do?

@halx99 halx99 merged commit bb6ac32 into axmolengine:release/2.x Apr 23, 2026
17 checks passed
@halx99 halx99 added this to the next milestone Apr 23, 2026
@halx99 halx99 added the enhancement New feature or request label Apr 23, 2026
@halx99
Copy link
Copy Markdown
Collaborator

halx99 commented Apr 23, 2026

Nothing, merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants