-
Notifications
You must be signed in to change notification settings - Fork 3
Examples
You can run the included examples that has different types of tests with different generated messages.
First, you need to install the example in the database. The files that are part of the examples are included in the sources in the next directory (not included en the released version): https://github.com/angoca/db2unit/blob/master/src/examples/sql-pl. (v2) Three files are part of the examples.
(v1)
cd examples
cd sql-pl
db2 -tf Tests_DB2UNIT_EXAMPLE.sql
(v2)
cd examples
cd sql-pl
db2 -tf Tests_DB2UNIT_EXAMPLE.sql
db2 -tf Tests_DB2UNIT_EXAMPLE_FAIL.sql
db2 -tf Tests_DB2UNIT_EXAMPLE_FAIL_ALL.sql
All sentences should have been run successfully.
And then, just call the test suite:
db2 "CALL DB2UNIT.RUN_SUITE('DB2UNIT_EXAMPLE')"
Then, you will have the following output (The order of the tests could not be the same if random execution is active):
Result set 1
--------------
TEST FINAL_STATE MICROSECONDS MESSAGE
---------------- ----------- ------------ ----------------------------------------------------------------
Before Suite - - Starting execution
TEST_9 Unstarted -1 Executing TEST_9
TEST_9 - -
TEST_9 - - Exception(2): SQLCode -438, SQLState TEST9-SQL0438N Application
TEST_2 Error 124000 Executing TEST_2
TEST_2 - -
TEST_2 - - Exception(2): SQLCode -438, SQLState 12345-SQL0438N Application
TEST_8 Failed 432000 Executing TEST_8
TEST_8 - - STRING_EQUALS
TEST_8 - - Different strings. The content of both strings is different
TEST_8 - - Expected : "A"
TEST_8 - - Actual : "B"
TEST_5 Failed 253000 Executing TEST_5
TEST_5 - - STRING_EQUALS
TEST_5 - - Strings have different lengths
TEST_5 - - Expected : "A"
TEST_5 - - Actual : "AB"
TEST_3 Error 202000 Executing TEST_3
TEST_3 - -
TEST_3 - - Exception(2): SQLCode -438, SQLState 12345-SQL0438N Application
TEST_4 Passed 97000 Executing TEST_4
TEST_1 Passed 50000 Executing TEST_1
TEST_6 Passed 23000 Executing TEST_6
TEST_7 Passed 23000 Executing TEST_7
After Suite - - Finishing execution
- - 9 tests were executed
- - 4 tests passed
- - 2 tests failed
- - 2 tests with errors
- - 1 unexecuted tests
30 record(s) selected.
Result set 2
--------------
TIME EXECUTION_ID STATUS MESSAGE
-------- ------------ --------------------- --------------------------------------------------------------
17:15:24 30405 Initialization db2unit is licensed under the terms of the GPL v3
17:15:24 30405 Initialization Execution of DB2UNIT_EXAMPLE with ID 30405
17:15:24 30405 Prepare Report The reports table created: DB2UNIT_EXAMPLE.REPORT_TESTS
17:15:30 30405 Calculating time Total execution time is: 5 seconds
4 record(s) selected.
Return Status = 1
The upper part shows a report about the current tests suite execution. The downer part is general information (common for all suite executions.)
Each time a tests suite is executed, it will have an execution ID.
This allows to see the results of a specific execution.
The execution ID is stored in the EXECUTION_REPORTS
table and in the REPORT_TESTS
table for the current suite.
The suite report has the name of the test, the status, the elapsed time, and messages about the execution.
The status means how the test was finished. The possible values are:
- Passed.
- Failed (the assertion execution failed).
- Error (the test failed before the assertion).
- Unexecuted (the before or beforeAll fixtures failed).
The messages always include the name of the test, but in the case of an error or a failure, it will include relative messages. In the case of a failed assertion, it will show the expected value and the actual value.
(v2) In version 2, the two extra files for the example shows when the setup fails and when the one_setup fails.
db2 "CALL DB2UNIT.RUN_SUITE('DB2UNIT_EXAMPLE_FAIL')"
db2 "CALL DB2UNIT.RUN_SUITE('DB2UNIT_EXAMPLE_FAIL_ALL')"
- db2unit in 5 minutes
- How to use
- Development
- Miscellaneous
IBM developerWorks:
Code analysis at Open HUB:
Support it: