JUnit Exception Testing

前端 未结 5 526
广开言路
广开言路 2020-12-14 19:54

Edit: Not JUnit 4 available at this time.

Hi there,

I have a question about \"smart\" exception testing with JUnit. At this time, I do it like this:

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-14 20:17

    The most concise syntax is provided by catch-exception:

    public void testGet() {
        SoundFileManager sfm = new SoundFileManager();
        ... // setup sound file manager
    
        verifyException(sfm, RapsManagerException.class)
           .getSoundfile(-100);
    
        verifyException(sfm, RapsManagerException.class)
           .getSoundfileByName(new String());
    }
    

提交回复
热议问题