I have a DAO class called PersonDAO and I am using it to get info about People from Database. I want to write unit test to check the database connection. This is what I have so far
@Test( expected= SQLException.class)
public void testDatabaseConnection()
throws Exception {
}
Also, how do I write unit test for findAll() method? This is what I have if I am storing people info in a map. But, I would like to know what changes if I have a database instead of a map
@Test
public void testFindAll()
throws Exception {
Map< Integer, PersonDTO > people = new LinkedHashMap<>();
people = PersonDAO.findAll();
assertEquals( PersonDTO.getTotalDept(), people.size() );
}
Basically, you are talking about integration tests if you want to test your DAO on "live" database.
In case you want to stay on JUnit, Mockito, EasyMock... are an answer.