jUnit same exception in different cases
Posted
by coubeatczech
on Stack Overflow
See other posts from Stack Overflow
or by coubeatczech
Published on 2010-03-14T22:29:07Z
Indexed on
2010/03/14
22:35 UTC
Read the original article
Hit count: 154
junit
Hi, I'm writing a jUnit test for a constructor that parses a String and then check numerous things. When there's wrong data, for every thing, some IllegalArgumentException with different message is thrown. So I would like to write tests for it, but how can i recognize what error was thrown? This is how can I do it:
@Test(expected=IllegalArgumentException.class)
public void testRodneCisloRok(){
new RodneCislo("891415",dopocitej("891415"));
}
and this is how I would like to be, but I don't know if it is possible to write it somehow:
@Test(expected=IllegalArgumentException.class("error1"))
public void testRodneCisloRok(){
new RodneCislo("891415",dopocitej("891415"));
}
© Stack Overflow or respective owner