Chapter 10. Testing and JDBC

 

This chapter covers

  • Which parts of your JDBC client code not to test
  • Testing your mapping between domain objects and ResultSets
  • Verifying SQL commands with the Gold Master technique
  • Using database meta data to write simpler tests
  • Managing test data in different databases and using DbUnit
  • Testing legacy JDBC code

There are those who would say that the database is the core of any “real” Java application. Although applications need data, many people have designed applications around the database, as though it were the center of the universe. This leads to high coupling between the application and its data sources and, as we have been saying throughout, high coupling and duplication are primary sources of frustration during Programmer Testing. In this chapter we present strategies and techniques for testing data components as well as offering ways to refactor your application towards a more testable design.

10.1. Test making domain objects from a ResultSet

10.2. Verify your SQL commands

10.3. Test your database schema

10.4. Verify your tests clean up JDBC resources

10.5. Verify your production code cleans up JDBC resources

10.6. Manage external data in your test fixture

10.7. Manage test data in a shared database

10.8. Test permissions when deploying schema objects

10.9. Test legacy JDBC code without the database

10.10. Test legacy JDBC code with the database

10.11. Use schema-qualified tables with DbUnit

10.12. Test stored procedures