The Spring DAO Wizard generates a TestNG unit test if the select the Create Unit Test for DAO option on the Specify Spring DAO Wizard page.
About DAO Unit Test Files
The DAO Test class is created in a separate source folder test/java as specified in the Spring DAO project setup. The unit test DAO Package is the same package name as the DAO class package name. The DAO unit test name is the DAO Class Name with the prefix of Test.
The following files are created to support the DAO unit test when you click Finish in the Spring DAO Wizard:
File | Description |
---|---|
src/config.jdbc.properties | Properties file with JDBC-related settings including connection information |
test/config/test-config.xml | TestNG Test Suite configuration file |
test/config/(DAO Class Name)-context.xml | Spring context file for the DAO unit test |
build.xml | Build file for the DAO and DAO unit test |
Running DAO Unit Test
- Right-click the build.xml file and select Run As > External Tools Configurations.
- Right-click Ant Build in the External Tools Configurations dialog and select New.
- Enter run-tests in Arguments.
- Click Apply in the External Tools Configurations dialog.
- Click Run in the External Tools Configurations dialog.
The results of the test are in the console and the index.html file in the main project directory.
About Editing the DAO Unit Test
The DAO unit test generated source code calls the DAO class. If the tested DAO class method has a parameter that is a numeric primitive, the value is set to zero in the test class. If the parameter is a class object, it is set to null. See the example below.
The parameter values for the unit test should be changed to values that make sense for the DAO method being tested to ensure the Unit test does not fail.
Using Teradata Session Manager
Your unit test generated code uses the Teradata Session Manager API if you select Use Teradata Session Manager in the Teradata Spring DAO Wizard. This is shown in the sample below.
Be sure to edit the parameter values to values that make sense for the unit test.
The Teradata Session Manager sets Query Band values for the current database transaction. To test this functionality, uncomment in the onSetupInTransaction method.
The method initThreadLocalContextForTest sets Query Band values in the ThreadLocalContext class. This in turns sets the Query Band values in the database transaction from the Teradata Session Manager.
The test method can be updated to verify Query Band values set for the database transaction by accessing the Session Connection and using the QueryBandUtils from the Teradata Commons Access JAR. This is shown in the example below.