// tutorial16.ot
group "tutorial_16";
subtest CompareNumbers(int a, int b)
{
verify(a == b);
}
test("Compare some numbers")
{
verify(CompareNumbers(2, 2));
verify(CompareNumbers(5, 5));
verify(CompareNumbers(3, 3));
verify(CompareNumbers(12, 12));
verify(CompareNumbers(22, 22));
}
test("Fail compare some numbers")
{
verify(CompareNumbers(2, 2));
verify(CompareNumbers(5, 5));
verify(CompareNumbers(3, 39));
verify(CompareNumbers(12, 12));
verify(CompareNumbers(22, 22));
}
A subtest takes a number of parameters, and can use verify() to perform tests and call other subtests. It is useful if you need several tests to do the same subtest, or if you need to test something with different values in one test. A normal test cannot call another test, so a subtest is useful in that case. Subtests can have finally {} clauses, just like tests, to clear up things when a verify fails.
========================================================================= Opera Testsuite ========================================================================= ========================================================================= E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial16.ot(2): tutorial_16 ========================================================================= Compare some numbers .......................................... Passed Fail compare some numbers ..................................... FAILED E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial16.ot(6): 'a' should be equal to 'b' FAILED E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial16.ot(22): 'CompareNumbers(3,39)' should be true ========================================================================= 2 tests run, 1 test failed, 0 tests skipped, 1 test OK Place a breakpoint in testsuite_break_here() to debug the failed test =========================================================================