3.0 KiB
3.0 KiB
Testing Guide
This project uses a combination of C++-based unit/functional tests and TypeScript-based end-to-end (E2E) tests to ensure code quality and correctness.
1. Unit & Functional Tests (C++/Google Test)
The C++ tests are built on the Google Test framework and are designed to test individual classes and functions in isolation.
- Location: All C++ tests are located in the
applications/tests/directory. - Test Scaffolding: A common test fixture is defined in
applications/tests/commons-test.handapplications/tests/commons-test.cpp. This scaffolding provides a headlessAppinstance, which is useful for testing components that rely on the application context. - Example: See
applications/tests/block_test.cppfor an example of how to write a test and use theAppTestfixture.
How to Run
To run the entire C++ test suite, use the corresponding npm script from the project root:
npm run test:core
This command will:
- Compile the test executable (
core_tests). - Run the tests using CTest.
How to Add a New Test
- Create a new
_test.cppfile inside theapplications/tests/directory. - Include
"commons-test.h"and any other necessary headers. - Write your tests using the Google Test
TEST_Fmacro, inheriting from theAppTestfixture if you need an application instance. - Add the name of your new file to the
add_executablecommand inapplications/tests/CMakeLists.txt.
2. End-to-End Tests (TypeScript/Vitest)
The E2E tests are built with Vitest and are designed to test the compiled command-line application (nodehub_d.exe) as a whole.
- Location: All E2E tests are located in the
tests/directory at the project root. - Test Runner: A helper function for executing the binary is located in
tests/commons.ts. This helper manages the command-line arguments and process execution. - Example: See
tests/e2e.test.tsfor an example of how to use therunClihelper to test the application's behavior.
How to Run
To run the entire E2E test suite, use the corresponding npm script from the project root:
npm run test:e2e:core
This command will invoke Vitest, which will discover and run all *.test.ts files inside the tests/ directory.
How to Add a New Test
- Create a new
_test.tsfile inside thetests/directory. - Import
describe,it, andexpectfrom"vitest", and therunClihelper from"./commons". - Write your tests. Each test should call
runCliwith the desired command-line arguments and then useexpectto assert the correctness of thestdout,stderr, or exitcode.