How to create unitary tests

From KratosWiki
Revision as of 12:08, 22 February 2016 by Roigcarlo (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Under construction

Kratos Multiphysics has a mechanism to automatically test your code called "KratosUnittest". If you are familiar with python, this module is basically an extension of Unittest and you can expect to find every functionality that exists on in as well in KratosUnittest.

In order for your application to be robust, is recommemded that you add unittests to it. Here we present some guidelines on how to do it.

How to run tests

Kratos unittest are executed using the "run_tests.py" script located in the "python_scripts" folder.

Usage is the following:

python run_tests.py

you can specify the following options:

-l,--level:        Select the suit. Values: "All", "Nighlty", "Small"(default)
-v,--vervosity:    Select the vervosity level of the output. Values: 0, 1 (default) , 2
-a,--applications: List of applications to run separated by ":". For example "-a KratosKore:IncompresibleFluidApplication"
                   All applications compiled are run by default.

Basic structure

Tests are defined in a python script. To keep tests organized we recommend you to create the tests in your "application/tests/" directory.

Tests are organized in suits. Suits are collection of tests that will be run together as a package. In Kratos, we define three basic suits:

  • All: which should contain all the tests
  • Nighlty: which should contain a set of tests that could be executed in less than 10 min
  • Small: which should contain a set of tests that could be executed in less than 1 min


All applications should implement this packages as they can be automatically run, for example in the "nighlty" runs. In order to add tests you should create at least a couple of files, one to define the tests

and one to define the suits:

"application/tests/test_NAME_OF_OUR_APPLICATION.py"


for example:

kratos/applications/example_application/tests/test_example_application.py


This file will define the suits to run the tests. We define three different levels of suits in kratos:

  • All: which should contain all the tests
  • Nighlty: which should contain a set of tests that could be executed in less than 10 min
  • Small: which should contain a set of tests that could be executed in less than 1 min
Personal tools
Categories