Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of ExternalResource and TemporaryFolder in JUnit 5?

According to the JUnit 5 User Guide, JUnit Jupiter provides backwards compatibility for some JUnit 4 Rules in order to assist with migration.

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.

The guide goes on to say that one of the rules is ExternalResource, which is a parent for TemporaryFolder.

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?

like image 685
Thunderforge Avatar asked May 18 '17 23:05

Thunderforge


1 Answers

Interesting article by author of TemporaryFolderExtension for JUnit5

and

his code repo on github

JUnit5.0.0 is now in general release so let's hope they turn their attention to making the experimental stuff production-ready.

Meanwhile, it seems the TemporaryFolder rule will still work with JUnit5 docs

use this:

@EnableRuleMigrationSupport
public class MyJUnit5Test {

and this:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-migrationsupport</artifactId>
    <version>5.0.0</version>
</dependency>
like image 53
Adam Avatar answered Oct 17 '22 20:10

Adam