JUnit custom rules

JUnit 4.7 introduces the concept of custom rules:

http://www.infoq.com/news/2009/07/junit-4.7-rules

There are a number of built-in JUnit rules, including TemporaryFolder, which help by cleaning folders after running the test:

@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();

Here is a complete list of built-in rules:

http://kentbeck.github.com/junit/javadoc/latest/org/junit/rules/package-summary.html

I am interested to know what user rules exist where you work, or what useful user rules you are currently using?

+3
source share
1 answer

I used @Rule to retest: @ Rule: 在 JUnit4 δΈ­ εˆ©η”¨ Rule

Sorry, this is Chinese, but the code and comment are in English :)

+2
source

Source: https://habr.com/ru/post/1744254/


All Articles