How to create own annotation for junit that will skip test if concrete exception was thrown during execution?

后端 未结 4 1414
逝去的感伤
逝去的感伤 2020-12-19 11:20

My application have several execution modes, and in 1 mode it is normal that some of my tests will throw a concrete exception. I need to annotate this methods with something

4条回答
  •  旧巷少年郎
    2020-12-19 11:49

    I searched for the docs about JUnit and it appears that from version 4.9 they have introduced what they call test rules (see TestRule). You may start from this.

    The ExpectedException class marked as @Rule could be of some help in order to check for exceptions thrown but not mandatory for the test to pass.

    For more advanced usage I cannot say for the moment as I've just discovered it.

提交回复
热议问题