From Koha Wiki
This documentation needs reviewed (written during kohacon12 after Chris(c) presentation).
A unit test is a piece of code that test a little part of code (input / outputs). It is a must have practice used in software that provide more quality and consistency to the code. Have a look to eXtreme programming for example.
This subject is close to Continuous_Integration.
Tests generally use Test::More and are kept in two folders:
- t stands for tests on code and unit tests
- "real" unit tests compare got and expected value of subs
- first level is safe for launching everywhere
- in db_dependent be carefull, it affect your current database in $KOHA_CONF
- Have a look to t/00-deprecated.t t/00-load.t t/check_databaseversion.t
- For more tricky (database) tests have a look to t/db_dependent/XISBN.t t/db_dependent/Barcodes.t
- TEST_QA must be set to 1 for 00-testcritics.t runs
- (create_db / clean_db should be the good practice but it does not work)
- xt stands for authoring code indentation, and sysprefs tests.
- free for all which can help consistencies / syntax (not functionnal testing)
- run it anywhere, no data modify
You can run a test by simply calling it with perl or using prove tool.
Howto run a test
Howto run all tests
Run tests without modifying database (everywhere, safety)
you@local ~/koha $ prove t
Run db dependent tests (/!\ Only on development computer!)
you@local ~/koha $ prove t/db_dependent
Each time you want to submit a patch run:
you@local ~/koha $ prove t you@local ~/koha $ prove xt
You must have for both:
All tests successful.