Skip to content

Automated testing of SolarTherm code

John Pye edited this page Oct 12, 2021 · 21 revisions

Outdated -- we are in the process of migrating to the Github Actions platform -- currently in the 'master-m' branch of our code, which will shortly be merged to the master branch.

We use the Travis framework (docs), for automated testing of the SolarTherm code. The Travis configuration is set up in .travis.yml, which specifies the steps to set up OpenModelica, Python 2.7 etc. on a Ubuntu 12.04 virtual machine ('precise' -- we want to update this to 16.04 ASAP), then to compile and install our SolarTherm code and finally to test it.

The Travis configuration .travis.yml specifies ctest -V as the command that actually runs all the test cases, once everything is built/installed (read more about testing with CTest)

Tests are defined in tests/CMakeLists.txt, which in turn calls on just one test which is called TestSolarTherm and is run using ./run_tests. This command in turn runs tests/run_tests, which is a Bash script that runs python -m unittest followed by a list of the filename stems of all the *.py files in the tests/ directory (read more about the Python unittest framework).

The various Python scripts in the tests directory make use of our Python automation-of-Modelica modules (e.g. simulation, postproc etc.) in src/python/scripts. These modules and classes make it fairly nice and easy to load and run Modelica models and check what the results are (although further improvements are definitely possible, e.g. automated generation of result .mat filename, perhaps).

There are also various Modelica files in this tests directory; these files are referenced by corresponding Python test scripts e.g. TestOptimisation.mo is called by TestOptimisation.py.

The following briefly walks you through how to run a test case in the tests directory. First of all, the environment variables should be activated through the following commad:

cd ~/solartherm/examples
. ../src/env/st_local_env

Before running a test case, make sure the Cmake software has been installed in the .local directory of your machine using the following command:

cd solartherm
cmake -DCMAKE_INSTALL_PREFIX=~/.local && make -j4 install

Then, simply go to the tests directory and run a test case as follows (e.g. TestSolarPosition.py which tests the position of the Sun based on a set of data points taken as an input):

cd ~/solartherm/tests/ 
ctest -v TestSolarPosition.py

Travis tests are run automatically when changes are committed to the SolarTherm code (please see the SolarTherm tests build history on Travis CI). The results are reported to our Gitter feed as well as via the small badge on our main page on Github.