tags:

views:

80

answers:

1
+2  Q: 

JUnit Custom Rules

JUnit 4.7 introduced 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 helps by clearing up folders after a test has been run:

@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();

There's a full list of built in rules here:

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

I'm interested in finding out what custom rules are in place where you work or what useful custom rules you currently use?

+2  A: 

I used @Rule for repeated test: @Rule: 在JUnit4中利用Rule

Sorry, It's Chinese, but code and comment are English:)

卢声远 Shengyuan Lu