... | ... | @@ -7,12 +7,19 @@ Unit testing is an essential part of the development process for OPAL. |
|
|
Also note that tests are code that we need to edit, etc, so tests should obey any
|
|
|
link:For%20Developers/CodingStyle[relevant style guides].
|
|
|
|
|
|
== Quick Start
|
|
|
== C++ Quick Start
|
|
|
|
|
|
* Run `tests/tools/install_gtests.bash` to install gtest framework (does not work on macs)
|
|
|
* Run `build-recipes` to build `300-gtest`
|
|
|
* From the root opal source directory run `cmake -DBUILD_OPAL_UNIT_TESTS=1`
|
|
|
* Run `tests/opal_unit_tests` to run the unit tests
|
|
|
|
|
|
== PyOpal Quick Start
|
|
|
|
|
|
* From the root opal source directory run `cmake -DBUILD_OPAL_PYTHON=1`
|
|
|
* Don't forget to run `make install` to install python
|
|
|
* Either: Run `python tests/opal_src/PyOpal/test_runner.py` to run all the unit tests
|
|
|
* Or: Run `python tests/opal_src/PyOpal/path/to/a_unit_test.py` to run a specific unit test
|
|
|
|
|
|
== Setting up the tests
|
|
|
|
|
|
In OPAL we use the google testing framework which has some convenience functions for e.g. equality testing in the presence of floating point errors, setting up common test data, etc.
|
... | ... | @@ -41,6 +48,18 @@ In general: |
|
|
* Code which is in src/Classic should have tests in `tests/classic_src`
|
|
|
* Other code should have tests in `tests/opal_src`
|
|
|
|
|
|
== PyOpal tests
|
|
|
|
|
|
Within the tests area are some specific tests for the OPAL python API. These tests are a mixture of unit tests and integration tests (i.e. testing the pyopal workflow), but they are all quick to run. There is also a slower test for code style. Tests are implemented in python.
|
|
|
|
|
|
Individual tests use the built-in python unittest package. Tests are implemented as instances of ``unittest.TestCase``. Tests should be executable as a standalone test by calling them as scripts from the command line, like ``python tests/opal_src/PyOpal/path/to/a_unit_test.py``.
|
|
|
|
|
|
Some tests execute the main OPAL workflow. Unfortunately, once finished OPAL tends to leave a lot of things lying about in memory which can cause problems in subsequent tests. In order to combat this, a small wrapper class has been written which wraps some tests in a forked process using os.fork. Details can be found at ``src/PyOpal/PyPython/encapsulated_test_case.py``
|
|
|
|
|
|
There exist set of style tests check that code is written in a way compatible with the official python style and performs some static code checks. These are executed by doing ``python tests/opal_src/PyOpal/test_pylint.py``.
|
|
|
|
|
|
All of the tests can be run using the test runner, ``python tests/opal_src/PyOpal/test_runner.py``. Note that this does run the pylint tests, which can be slow. To disable pylint execution, pass ``--do_not_run_pylint`` as a command line argument.
|
|
|
|
|
|
== More on the unit test concept
|
|
|
|
|
|
The idea behind unit tests is to test at the level of the smallest unit that the code does what we think. We test at the smallest unit so that:
|
... | ... | |