This is just a quickstart tutorial. See also the complete documentation.
Run an existing Test
The .sql files in the test directory contain some Test Cases and a Test Suite which test some parts of STK/Unit. You can use them as an example.
You can run a test and get the results as a human-readable string. Let's do it with test_stk_unit Test Case and stk_unit Test Suite (please, note that stk_unit automatically runs test_stk_unit, but we use them both as an example);
CALL stk_unit.tc('test_stk_unit');
CALL stk_unit.ts('stk_unit');
The results should appear in your client. If they don't, please use mysqld for this tutorial.
A summary will appear in the command-line client. There should be several Passes, 0 Fails, and 0 Exceptions. But if something gone wrong (Fails or Exceptions), you will see a list of the problems.
In the Screenshots page, screenshots are avaible for test execution and results reading from the command line.
Creating your tests
Writing a new Test Case
A Test Case is a database whose name starts with 'test_' (lowercase) and which containt some Base Tests.
So, first create the database:
CREATE DATABASE 'test_my_tc';
Now, write one simple Base Test. Base Tests are Stored Procedure with no parameters, located in the Test Case's database, having a name that starts with 'test_' (lowercase).
You can copy one of the simplest Base Tests from test_stk_unit, and adapt it to your needs.
Assertions
Every Base Test usually contains at least one assertion. The simplest assertion you can use is assert_true(). Examples:
CALL stk_unit.assert_true(TRUE, 'This message will not appear'); -- this will pass
CALL stk_unit.assert_true(FALSE, 'Dont worry: this assert was meant to fail!'); -- this will fail
Expectations
You can use expectations to tell STK/Unit if the test is expected to issue an error:
CALL stk_unit.except_any_exception();
Or you can say that an error may occur, but it shouldn't be taken into account:
CALL stk_unit.ignore_all_exceptions();
Writing a new Test Suite
If you have several Test Cases and sometimes you want to run them at once, you may want to write a Test Suite. A Test Suite is a Stored Procedure located in the test_suite database. Test Suite names should never start with an underscore (_).
Example:
CREATE PROCEDURE my_ts
BEGIN
CALL stk_unit.run_test_case('test_one');
CALL stk_unit.run_test_case('test_two');
END;