How does Junit @Rule work?

前端 未结 4 1447
予麋鹿
予麋鹿 2020-11-28 18:40

I want to write test cases for a bulk of code, I would like to know details of JUnit @Rule annotation feature, so that I can use it for writing test cases. Ple

4条回答
  •  春和景丽
    2020-11-28 19:04

    Rules are used to add additional functionality which applies to all tests within a test class, but in a more generic way.

    For instance, ExternalResource executes code before and after a test method, without having to use @Before and @After. Using an ExternalResource rather than @Before and @After gives opportunities for better code reuse; the same rule can be used from two different test classes.

    The design was based upon: Interceptors in JUnit

    For more information see JUnit wiki : Rules.

提交回复
热议问题