55 lines
3.0 KiB
Markdown
55 lines
3.0 KiB
Markdown
# 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/`](../../applications/tests/) directory.
|
|
- **Test Scaffolding:** A common test fixture is defined in [`applications/tests/commons-test.h`](../../applications/tests/commons-test.h) and [`applications/tests/commons-test.cpp`](../../applications/tests/commons-test.cpp). This scaffolding provides a headless `App` instance, which is useful for testing components that rely on the application context.
|
|
- **Example:** See [`applications/tests/block_test.cpp`](../../applications/tests/block_test.cpp) for an example of how to write a test and use the `AppTest` fixture.
|
|
|
|
### How to Run
|
|
|
|
To run the entire C++ test suite, use the corresponding `npm` script from the project root:
|
|
|
|
```bash
|
|
npm run test:core
|
|
```
|
|
|
|
This command will:
|
|
1. Compile the test executable (`core_tests`).
|
|
2. Run the tests using CTest.
|
|
|
|
### How to Add a New Test
|
|
|
|
1. Create a new `_test.cpp` file inside the [`applications/tests/`](../../applications/tests/) directory.
|
|
2. Include `"commons-test.h"` and any other necessary headers.
|
|
3. Write your tests using the Google Test `TEST_F` macro, inheriting from the `AppTest` fixture if you need an application instance.
|
|
4. Add the name of your new file to the `add_executable` command in [`applications/tests/CMakeLists.txt`](../../applications/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/`](../../tests/) directory at the project root.
|
|
- **Test Runner:** A helper function for executing the binary is located in [`tests/commons.ts`](../../tests/commons.ts). This helper manages the command-line arguments and process execution.
|
|
- **Example:** See [`tests/e2e.test.ts`](../../tests/e2e.test.ts) for an example of how to use the `runCli` helper 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:
|
|
|
|
```bash
|
|
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
|
|
|
|
1. Create a new `_test.ts` file inside the [`tests/`](../../tests/) directory.
|
|
2. Import `describe`, `it`, and `expect` from `"vitest"`, and the `runCli` helper from `"./commons"`.
|
|
3. Write your tests. Each test should call `runCli` with the desired command-line arguments and then use `expect` to assert the correctness of the `stdout`, `stderr`, or exit `code`.
|