Converting SQL script Tests to JUnit

Notes on how to easily convert SQL scripts to running under JUnit using .org.apache.derbyTesting.functionTests.util.ScriptTestCase. ScriptTestCase runs a SQL script against a database and compares the output to a single master file (canon), thus its mode of execution is very similar to running the SQL script under the old harness..

Is the test suitable?

If the test has any of these attributes then most likely it is not suitable for conversion as a SQL script and should instead be converted to a test case using JDBC and BaseJDBCTestCase.


See LangScripts and NistScripts in the lang and nist functional test packages.


Language Tests

Run the script using LangScripts, e..g to run the script insert.sql execute

java org.apache.derbyTesting.functionTests.tests.lang.LangScripts insert

Other Tests

If the package does not contain a JUnit test that extends ScriptTestCase then create one following the examples. Run the script as a JUnit test and proceed to checking the output.

Checking the Output

Test Passes!

If you are lucky then the test passed which means the output under ScriptTestCase matched the output under the old harness. The test is ready to be added to JUnit, ensure that it is run by the _Suite suite in the same package, remove the test from the old harness suite files and commit or submit the patch.

Test Fails

The test will fail at the first line in the output that does not match the canon. The output from the test is written as a .out file with the name of script under the fail folder. It may be a couple of levels deep, depending on the extension of ScriptTestCase. For example running the insert test with LangScripts resulted in the output file in fail/Embedded/LangScripts/insert/insert.out. Compare this file with the master file from java/testing/org/apache/derbyTesting/functionTests/master using diff or similar utility. Possible reasons for the failure are:

If the diff only contains the above items then you can copy the output into the master file folder and re-run the test to see it pass. Commit or submit the patch!

If the output contains any of these diffs then some change is needed or the test may be unsuitable to run using ScriptTestCase:

ConvertSqlScriptTestsToJunit (last edited 2009-09-20 22:11:58 by localhost)