net.sourceforge.sqlunit
Class SQLUnit

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by net.sourceforge.sqlunit.SQLUnit
All Implemented Interfaces:
junit.framework.Test

public class SQLUnit
extends junit.framework.TestCase

The SQLUnit class is actually a JUnit test case and is the main program which is called by the SQLUnit user. Instead of executing predefined tests in sequence, the SQLUnit test will parse an XML input file containing the test information and execute tests dynamically.

Version:
$Revision: 1.56 $
Author:
Sujit Pal (spal@users.sourceforge.net)

Constructor Summary
SQLUnit(java.lang.String name)
          Instantiates a new instance of SQLUnit.
 
Method Summary
 void runTest()
          Called by Test.run() or Test.runBare() from the SQLUnit task.
 void setAntSymbols(java.util.Hashtable projectProps)
          Sets any symbols that were set for SQLUnit within the Ant build.xml file, if SQLUnit is invoked using the SQLUnit Ant task.
 void setConnection(java.sql.Connection conn)
          Allows a client other than the sqlunit build task to set the database connection to use for the test.
 void setDebug(boolean debug)
          Sets the debug attribute from the SQLUnit task.
 void setHaltOnFailure(boolean haltOnFailure)
          Sets the haltOnFailure attribute from the SQLUnit task.
 void setReporter(IReporter reporter)
          Sets the IReporter object from the SQLUnit task.
 void setTestFile(java.lang.String testFile)
          Sets the testFile attribute from the SQLUnit task.
static junit.framework.Test suite()
          Returns the TestSuite object to run.
 void testWrapper()
          The main testing class which dynamically processes the input XML file.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, name, run, run, runBare, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assert, assert, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertNotNull, assertNotNull, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SQLUnit

public SQLUnit(java.lang.String name)
Instantiates a new instance of SQLUnit.

Parameters:
name - the name of the TestCase object.
Method Detail

suite

public static junit.framework.Test suite()
Returns the TestSuite object to run.

Returns:
a Test object.

setHaltOnFailure

public final void setHaltOnFailure(boolean haltOnFailure)
Sets the haltOnFailure attribute from the SQLUnit task.

Parameters:
haltOnFailure - controls the behavior of the test. If true, the test will stop processing the first time a test fails. If false, the test will continue on till all files declared in the sqlunit task is consumed.

setDebug

public final void setDebug(boolean debug)
Sets the debug attribute from the SQLUnit task.

Parameters:
debug - prints trace information using log4j if set to true.

setReporter

public final void setReporter(IReporter reporter)
Sets the IReporter object from the SQLUnit task.

Parameters:
reporter - the IReporter object to log messages to.

setTestFile

public final void setTestFile(java.lang.String testFile)
Sets the testFile attribute from the SQLUnit task.

Parameters:
testFile - the test file to use for the test.

setConnection

public final void setConnection(java.sql.Connection conn)
Allows a client other than the sqlunit build task to set the database connection to use for the test. Useful in case the same file needs to be used to test multiple database instances.

Parameters:
conn - the database connection to use.

setAntSymbols

public final void setAntSymbols(java.util.Hashtable projectProps)
Sets any symbols that were set for SQLUnit within the Ant build.xml file, if SQLUnit is invoked using the SQLUnit Ant task.

Parameters:
projectProps - a Hashtable of Ant properties set in the calling build.xml file.

runTest

public final void runTest()
                   throws SQLUnitException
Called by Test.run() or Test.runBare() from the SQLUnit task. Runs the SQLUnit test and collects the results in SQLUnitResult.

Overrides:
runTest in class junit.framework.TestCase
Throws:
SQLUnitException - if one is thrown by the test.

testWrapper

public final void testWrapper()
                       throws SQLUnitException
The main testing class which dynamically processes the input XML file. Can throw an exception. Exceptions of class SQLUnitException are treated as application error messages and appear on the STDERR instead of being thrown up in the JVM's stack trace.

Throws:
SQLUnitException - if one is thrown by underlying methods.