Test the code#

Testing the code is super important when launching the app for the first time but also when modifying it.

Prerequisites#

The following prerequisites are mandatory:

  • Python 3.11 is installed, and you activated the python environment with the requirements specified in requirements.txt;

  • You compiled the code properly with CMake (see Compile the code)

Run the tests#

Run the tests by hitting the following lines.

On Windows:

.\tests\meshchecker_tests.exe
.\tests\hydroflow_tests.exe
python tests/pytest_runner.py

On linux or MacOS:

tests/meshchecker_tests
tests/hydroflow_tests
python3 tests/pytest_runner.py

All the tests should pass before you commit and push anything.

Add tests to Watlab#

The test folder is organized as follows.

tests
  ├── cpp_cases    # test cases related to hydroflow.cpp
  ├── data         # benchmarks for watlab testing purposes
  ├── meshchecker  # test cases related to meshchecker.cpp
  ├── meshes       # meshed used for testing watlab
  ├── py_cases     # test cases for watlab
  ├── rasters      # raster cards for end-to-end testing
  ├── scripts      # deprecated
  ├── hydroflow-tests    # runs all the c++ tests related to hydroflow
  ├── meshchecker-tests  # runs all the c++ tests related to meshchecker
  ├── pytest_runner.py   # runs all the python tests

The tests are groupes in files containing the same elements. For instance, the tests for meshchercker are grouped in the so-named folder. Each file of this folder tests a class or a group of features. Please consider placing your new test in the right file, or create a new file if you created a new class.

Each feature should be tested before it is pushed.

Tests in python#

Python tests are run with unittest. Documentation is available in here. If you add a new class of test, consider adding it to the suite of the file tests/pytest_runner.py.

Tests with C++#

Tests are written with Google’s framework Google Test <https://google.github.io/googletest/>_ and compiled with CMake (and not Bazel, but if you want to, feel free). Each class is tested in one file. The tests are automatically added to the main().