jUnit same exception in different cases

前端 未结 2 2049
-上瘾入骨i
-上瘾入骨i 2021-02-05 23:08

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 di

2条回答
  •  甜味超标
    2021-02-05 23:32

    If you have JUnit 4.7 or above you can use this (elegant) way:

    @Rule
    public ExpectedException exception = ExpectedException.none();
    
    @Test
    public void testRodneCisloRok(){
        exception.expect(IllegalArgumentException.class);
        exception.expectMessage("error1");
        new RodneCislo("891415",dopocitej("891415"));
    }
    

提交回复
热议问题