JUnit 5中的ExternalResource和TemporaryFolder的等价物是什么? [英] What is the equivalent of ExternalResource and TemporaryFolder in JUnit 5?
问题描述
根据 JUnit 5用户指南,JUnit Jupiter为某些JUnit 4规则提供向后兼容性以帮助迁移。
According to the JUnit 5 User Guide, JUnit Jupiter provides backwards compatibility for some JUnit 4 Rules in order to assist with migration.
如上所述,JUnit Jupiter不会并且本身不支持JUnit 4规则。然而,JUnit团队意识到许多组织,特别是大型组织,可能拥有大型JUnit 4代码库,包括自定义规则。为了服务这些组织并实现渐进式迁移路径,JUnit团队决定在JUnit Jupiter中逐字支持一系列JUnit 4规则。
As stated above, JUnit Jupiter does not and will not support JUnit 4 rules natively. The JUnit team realizes, however, that many organizations, especially large ones, are likely to have large JUnit 4 codebases including custom rules. To serve these organizations and enable a gradual migration path the JUnit team has decided to support a selection of JUnit 4 rules verbatim within JUnit Jupiter.
该指南继续说其中一条规则是 ExternalResource ,它是 TemporaryFolder 。
The guide goes on to say that one of the rules is ExternalResource, which is a parent for TemporaryFolder.
然而,该指南遗憾的是没有继续说什么迁移路径是,或者对于那些编写新的JUnit 5测试的人来说是等价的。那么我们应该使用什么?
However, the guide unfortunately doesn't go on to say what the migration path is, or what the equivalent is for those writing new JUnit 5 tests. So what should we use?
推荐答案
JUnit5的TemporaryFolderExtension作者的有趣文章
和
JUnit5.0.0现已全面发布,所以我们希望他们把注意力转移到让生产准备就绪的实验性产品上。
JUnit5.0.0 is now in general release so let's hope they turn their attention to making the experimental stuff production-ready.
同时,似乎TemporaryFolder规则仍然适用于JUnit5 docs
Meanwhile, it seems the TemporaryFolder rule will still work with JUnit5 docs
使用此:
@EnableRuleMigrationSupport
public class MyJUnit5Test {
和此:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-migrationsupport</artifactId>
<version>5.0.0</version>
</dependency>
这篇关于JUnit 5中的ExternalResource和TemporaryFolder的等价物是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!