Actions

Regression and unit tests: Difference between revisions

From LimeSurvey Manual

No edit summary
Line 9: Line 9:
== Introduction ==
== Introduction ==


In an ideal world, a regression test is added every time a new bug is discovered. In that way you make sure you never have to fix the same bug twice.
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
To enable unit testing, you have to issue the command


$ touch enabletesting
<syntaxhighlight>
$ touch enabletests
</syntaxhighlight>


in the LimeSurvey root folder.
in the LimeSurvey root folder.


The test system uses [https://phpunit.de/ phpunit], which you need to install first.
The test system uses [https://phpunit.de/ phpunit], which you need to install first.
After you've done that, you should be able to write
<syntaxhighlight>
$ phpunit
</syntaxhighlight>
in the root folder to run the tests. This is an example of the output:
<syntaxhighlight>
$ phpunit
PHPUnit 5.6.2 by Sebastian Bergmann and contributors.
....                                                                4 / 4 (100%)
Time: 713 ms, Memory: 14.00MB
OK (4 tests, 24 assertions)
</syntaxhighlight>


== PHPUnit ==
== PHPUnit ==

Revision as of 12:09, 15 June 2017

  Warning : Every time you discover a new bug, you should add a regression test to make sure it does not appear again.


  Warning : NEVER run tests on a productive system. The tests WILL modify the database.


 Hint: Always make sure new code follows the PSR-2 standard for PHP. Use codesniffer and mess detector to catch common bugs and style fixes in your code.


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)

PHPUnit