JUnit自定义规则

时间:2010-05-06 00:15:53

标签: junit junit4

JUnit 4.7引入了自定义规则的概念:

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

有许多内置的JUnit规则,包括TemporaryFolder,它有助于在测试运行后清除文件夹:

@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();

这里有完整的内置规则列表:

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

我有兴趣了解您工作的自定义规则或目前使用的有用自定义规则?

1 个答案:

答案 0 :(得分:2)

我使用 @Rule 进行重复测试:@Rule: 在JUnit4中利用Rule

抱歉,这是中文,但代码和评论是英文:)