Regression and unit tests
From LimeSurvey Manual
Since LimeSurvey 2.65.6 you have the possibility to add unit tests to LimeSurvey.
Introduction
In an ideal world, a regression test is added every time a new bug is discovered. That way you make sure you never have to fix the same bug twice.
To enable unit testing, you have to issue the command
$ touch enabletests
in the LimeSurvey root folder.
The test system uses phpunit, which you need to install first.
After you've done that, you should be able to write
$ phpunit
in the root folder to run the tests. This is an example of the output:
$ phpunit
PHPUnit 5.6.2 by Sebastian Bergmann and contributors.
.... 4 / 4 (100%)
Time: 713 ms, Memory: 14.00MB
OK (4 tests, 24 assertions)
You can get some more information if you use the switch --testdox
:
$ phpunit --testdox
PHPUnit 5.6.2 by Sebastian Bergmann and contributors.
ls\tests\DateTimeForwardBack
[x] Q 1
ls\tests\DateTime
[x] Wrong input
[x] Correct date format
[x] Q 1
What can be tested?
Right now, there are tests for the expression manager and qanda. You cannot test Javascript yet, but it can be added.
Adding a test
First of all, make sure to head over to the phpunit web site and read the introduction.
When done with that, I will assume you want to add a new test for a question type. Tests for questions are stored in folder tests/questions
.
You should create a minimal survey to reproduce your bug. Export it as an lss file and put it in tests/data/surveys
. Then create a class for your test. Name the file the same as the class, like "DateTimeForwardBackTest.php". The class name must end with "Test", so phpunit can find it.
TODO