mardi 9 juin 2015

How do I write unit test (JUnit) to check Database connection using DAO class?

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() );
}

Aucun commentaire:

Enregistrer un commentaire