Skip to content

DevNotes_DevGuide_CodeTesting

Wojciech Potrzebowski edited this page May 25, 2020 · 6 revisions

Testing SasView code

There are three different ways to perform code testing in SasView depending on what part of functionality we are testing: core, models, GUI

  1. For sasview core, tests are located in sasview/test
  2. For 5.x GUI, tests are located in respective folders e.g for Fitting sasview/src/sas/qtgui/Perspectives/Fitting/UnitTesting/
  3. For sasmodels tests are part of model definition

General notes about tests

  • Unit tests should test one method only. This allows you to easily identify what failed if the test fails.
  • Unit tests should not be coupled together, therefore one unit test CANNOT rely on another unit test having completed first.
  • Unit tests should use small and simple data sets.
  • Tests should be fast, ideally really fast - certainly not more than a few seconds.
  • Untestable code is a code-smell, if you can't get the code under test it probably needs refactoring.
  • Weight your testing to be destructive rather than demonstrative. Destructive tests are more efficient in finding bugs.
  • Use long and descriptive names for testing functions. The reason is testing functions are never called explicitly. square() or even sqr() is ok in running code, but in testing code you would have names such as test_square_of_number_2(),test_square_negative_number(). These function names are displayed when a test fails, and should be as descriptive as possible.
  • Attributes of a good test: Fast, Clear, Isolated, Reliable
  • Models: Include at least one test for each model and PLEASE make sure that the answer value is correct (i.e. don't blindly use the function return value to set the test results; instead check against the paper or another program).
  • Models: Remember to test a model for critical values (e.g. q=0)
Clone this wiki locally