16

In the quest to solve this and somehow that, I was trying out to create packages to subdivide main and test classes and then to make use of compiler with added modules to execute the unit-tests. Not a very good way agreed, but just a hypothetical structure for now.

enter image description here

Few open questions as I proceeded further were:-

  • Add a JDK9 based module to the project.
  • Add JUnit5 to the classpath using IntelliJ's shortcut. (lib folder) [junit-jupiter-api-5.0.0.jar]

Q. Note that it brings along the opentest4j-1.0.0.jar to the lib/ folder. Why is that so, what is the other jar used for?

  • Add the classes and generate some tests method correspondingly.

  • Compile the sample project (shared just to draw a picture of the directory structure in use) using the command

    javac --module-path lib -d "target" $(find src -name "*.java")
    

    Results into warnings as -

warning: unknown enum constant Status.STABLE   
  reason: class file for org.apiguardian.api.API$Status not found 
warning: unknown enum constant Status.STABLE 
2 warnings

Note:-

I find the usage of junit-jupiter suspicious since if I comment out the code using JUnit and execute the same command, things seem to be working fine.

Libraries/Tools used if that might matter:-

  • junit-jupiter-api-5.0.0 with
  • Java version "9" (build 9+181)
  • IntelliJ 2017.2.5

Q. What could be a probable cause to such a warning? Moreover, I am unable to find the API.Status in my project and outside the project classes as well.

Naman
  • 27,789
  • 26
  • 218
  • 353
  • 2
    Sorry, I deleted my comment because I wasn't testing with intelliJ, and that is what you're asking about. I also can't find that `org.apiguardian` package any where, so my guess is that it has to do with intelliJ. – Jorn Vernee Oct 12 '17 at 07:39
  • 1
    See https://github.com/junit-team/junit5/issues/1065 for details. – Sormuras Oct 12 '17 at 08:59
  • @Sormuras Thanks for the link. Though that might answer `org.apiguardian.api` but its still not clear why does including the junit-jupiter to classpath brings along `opentest4j-1.0.0.jar`? – Naman Oct 12 '17 at 09:20
  • 1
    "JUnit Jupiter API" depends on it. See https://github.com/ota4j-team/opentest4j for the purpose of this _extra_ project/artifact. – Sormuras Oct 12 '17 at 09:34
  • @Sormuras Any idea about [this](https://stackoverflow.com/questions/46702273/warning-unknown-enum-constant-status-stable/46950496?noredirect=1#comment80850680_46950496) ? – Naman Oct 26 '17 at 10:39

2 Answers2

6

The compilation warning can simply be ignored. Moreover, it won't be appearing anymore starting with the version 5.1.0 (currently in development). It is all explained in Release Notes:

In 5.0.1, all artifacts were changed to have an optional instead of a mandatory dependency on the @API Guardian JAR in their published Maven POMs. However, although the Java compiler should ignore missing annotation types, a lot of users have reported that compiling tests without having the @API Guardian JAR on the classpath results in warnings emitted by javac that look like this:

warning: unknown enum constant Status.STABLE
reason: class file for org.apiguardian.api.API$Status not found

To avoid confusion, the JUnit team has decided to make the dependency to the @API Guardian JAR mandatory again.

For reference also see:

ᄂ ᄀ
  • 5,669
  • 6
  • 43
  • 57
4

1) opentest4j

opentest4j is a transitive dependency of junit-jupiter-api. See the dependency graph:

+--- org.junit.jupiter:junit-jupiter-api:5.0.1
     +--- org.opentest4j:opentest4j:1.0.0
     \--- org.junit.platform:junit-platform-commons:1.0.1

2) unknown enum constant Status.STABLE

You need to add following dependency: apiguardian-api.

For example in Gradle, you can do it via:

dependencies {
    testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.1'
    testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.0.1'
    testCompileOnly 'org.apiguardian:apiguardian-api:1.0.0'
}

But overall, dependency is build-tool-independent, so you can do it in plain IDE without Gradle, or Maven.

Vít Kotačka
  • 1,472
  • 1
  • 15
  • 40