6

It's not really coding question but I'm stuck on it. I start new Java project in Intelliji and add tests with JUnit5. In this tests I'm using @Role annotation for FakeSftpServerRule github library.

I added all jupiter dependencies I just can thought about them in the pom file:

<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-engine</artifactId>
    <version>1.6.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-launcher</artifactId>
    <version>1.6.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.5.2</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.vintage</groupId>
    <artifactId>junit-vintage-engine</artifactId>
    <version>5.6.0</version>
    <scope>test</scope>
</dependency>

It's the way to initialize the fake ftp:

@Rule
public final FakeSftpServerRule fakeSftpServer = new FakeSftpServerRule()
   .addUser(username, password)
   .setPort(port);

And I'm using regular other attributes, like @BeforeAll and @Test...

Running the tests throw this error:

Internal Error occurred. org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-vintage' failed to discover tests at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:189) at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:168) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58) Caused by: org.junit.platform.commons.JUnitException: Unsupported version of junit:junit: 4.11-beta-1. Please upgrade to version 4.12 or later. at org.junit.vintage.engine.JUnit4VersionCheck.checkSupported(JUnit4VersionCheck.java:39) at org.junit.vintage.engine.JUnit4VersionCheck.checkSupported(JUnit4VersionCheck.java:32) at org.junit.vintage.engine.VintageTestEngine.discover(VintageTestEngine.java:62) at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:181)

Now, by navigate to source I found that @BeforeAll and @Test annotations point on junit-jupiter 5.5.2 but @Role point on junit 4.11 (beta-1).

How can I get rid from junit 4.11 and update it to the latest version?

halfer
  • 19,824
  • 17
  • 99
  • 186
AsfK
  • 3,328
  • 4
  • 36
  • 73
  • 2
    https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4 -- and also please align the versions of JUnit Platform (1.6.1), Jupiter, and Vintage: 5.6.1 Browse/copy starter project here: https://github.com/junit-team/junit5-samples – Sormuras Apr 05 '20 at 06:11
  • 1
    If you are getting unexpected dependencies, it's often useful to run `mvn dependency:tree` to see where they are coming from. – tgdavies Apr 05 '20 at 06:17
  • Thanks both! @Sormuras, I see you link, thanks! so `@Rule` is not supported in Junit5, thereare some workarounds but I decide to downgrade to junit4. Thanks! – AsfK Apr 05 '20 at 06:59

0 Answers0