Firstly, if you use the database, you are no longer testing the device. You have entered integration (for connection configuration) or a functional earth test. And these are very different animals.
The connection method should definitely be separated from the data sample. In fact, your connection must be connected to the factory so that you can combine it. As for connection testing, really all you can check is that your configuration is correct by establishing a connection to the database. You should not try to check your connection pool, as it probably should be a library that someone wrote (dbcp or c3p0). Furthermore, you probably cannot verify this, since your unit / integration / function tests NEVER connect to a production-level database.
How to check if your data access code works. This is functional testing and includes many frameworks and support. You need a separate test database, the ability to create a schema on the fly during testing, insert any static data into the table and return the database to a known clean state after each test. In addition, this database must be created and run in such a way that two people can run tests at once. Especially if you have more than one developer, plus an automatic test box.
Statements must be against data that is either static data (for example, a list of states that often does not change) or data that was inserted during the test and the afterwords are removed so that they do not interfere with other tests.
EDIT: As already noted, there is reason for this. DBUnit is pretty common.
source share