maximus
maximus

Reputation: 11524

How to trace the values in a junit test?

I am running a simple test case where I test if there is no id in the db and i get an expected exception back.

But it does not work. So my question is how to trace the values of a test in junit? Any good solutions?

I appreaciate your answer!!!

UPDATE: test case:

@Test(expected = SQLException.class)
public void testDeleteID(){
    ArrayList<Produkt> queryResult=new ArrayList<Produkt>();
    shandler.deleteProdukt(666);
    queryResult=shandler.findAll();

}

IDE: eclipse

Upvotes: 0

Views: 2350

Answers (2)

nano_nano
nano_nano

Reputation: 12523

I think you try to catch a nested Exception. Change your code to that and take a look in the stacktrace for the concrete exception:

@Test(expected = Exception.class) 
public void testDeleteID(){
 ArrayList<Produkt> queryResult=new ArrayList<Produkt>();
 shandler.deleteProdukt(666);
 queryResult=shandler.findAll();  
} 

Another way: remove the "expected" and surround the database operation with a try-catch block.

@Test
public void testDeleteID(){
 ArrayList<Produkt> queryResult=new ArrayList<Produkt>();
 try{
   shandler.deleteProdukt(666);
   queryResult=shandler.findAll();  
   assertTrue(false);
 }catch(Exception ex){
   assertTrue(true);
 }
} 

but the first one is the better solution. I think you catch the wrong exception.

Upvotes: 1

belial
belial

Reputation: 321

Are you using IDE such as Eclipse? Add a break point, and run as Debug.

Upvotes: 4

Related Questions