Gradle 5 RC1 and JUnit 5

Hi

I tried to migrate from Gradle 4.8 to Gradle 5.0 RC1 and everything seemed fine except the unit-testing.
I got compilation errors when running JUnit 4 tests (I have both JUnit 4/JUnit 5 tests):

error: cannot find symbol
                assertNotNull(fields);
                ^
  symbol:   method assertNotNull(List<String>)
  location: class ReflectionUtilTest

Although I have necessary static import (import static org.junit.Assert.*:wink: in the ReflectionUtilTest class.

Here is a part of my Gradle script (related to tests):

  dependencies {
    testCompile 'org.junit.jupiter:junit-jupiter-api:5.2.0'
    testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.2.0' 
    testCompile 'org.junit.vintage:junit-vintage-engine:5.2.0'
}
test {
   useJUnitPlatform {
       includeEngines 'junit-vintage'
       includeEngines 'junit-jupiter'
   }
}

Thanks,
Sergey

You also need the dependencies for JUnit 4

testCompileOnly group: 'junit', name: 'junit', version: '4.12'

Hi @DJViking

Why do I need that? junit-vintage-engine dependency has transitive dependency to junit:junit:4.12

+--- org.junit.vintage:junit-vintage-engine:5.2.0
|    +--- org.apiguardian:apiguardian-api:1.0.0
|    +--- org.junit.platform:junit-platform-engine:1.2.0 (*)
|    \--- junit:junit:4.12
|         \--- org.hamcrest:hamcrest-core:1.3

Sorry about that. I wasn’t aware it came with the vintage dependency.

The vintage engine only has a runtime dependency in junit4. You shouldn’t have a compile dependency on the engine. Instead you should have a compile dependency on junit4 and a runtime dependency on the vintage engine.

1 Like

Hi @st_oehme

Thank you for the answer. JUnit 5 documentation states the same. https://junit.org/junit5/docs/current/user-guide/#running-tests-build