junit-insights icon indicating copy to clipboard operation
junit-insights copied to clipboard

Tests won't run if the plugin is added

Open gotson opened this issue 4 years ago • 2 comments

I am trying to use the plugin in my project, but once i add the dependency to my build.gradle.kts, tests do not run anymore:

org.gradle.api.internal.tasks.testing.TestSuiteExecutionException: Could not complete execution for Gradle Test Executor 3.
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:63)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy2.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:132)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
	at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:412)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: org/junit/platform/launcher/TestExecutionListener
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:370)
	at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
	at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
	at java.lang.Iterable.forEach(Iterable.java:74)
	at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:94)
	at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:67)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:97)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
	... 25 more
Caused by: java.lang.ClassNotFoundException: org.junit.platform.launcher.TestExecutionListener
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 49 more

This is my build.gradle.kts file, in which i added the following:

  • In the dependencies block:
testImplementation("de.adesso:junit-insights:1.1.0")
  • and also:
tasks {
  withType<Test> {
    useJUnitPlatform()
    systemProperty("spring.profiles.active", "test")
    systemProperty("de.adesso.junitinsights.enabled", "true")
    systemProperty("junit.jupiter.extensions.autodetection.enabled", "true")
  }
}

I am using Gradle 6.3.

gotson avatar May 28 '20 02:05 gotson

With Maven 3.6 and

    <dependency>
      <groupId>de.adesso</groupId>
      <artifactId>junit-insights</artifactId>
      <version>1.1.0</version>
      <scope>test</scope>
    </dependency>
  <!-- ... -->
    <repository>
        <id>jcenter</id>
        <url>https://jcenter.bintray.com/</url>
    </repository>
  <!-- ... -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <systemPropertyVariables>
            <de.adesso.junitinsights.enabled>false</de.adesso.junitinsights.enabled>
            <junit.jupiter.extensions.autodetection.enabled>false</junit.jupiter.extensions.autodetection.enabled>
            <de.adesso.junitinsights.reportpath>reports/</de.adesso.junitinsights.reportpath>
          </systemPropertyVariables>
        </configuration>
      </plugin>

I got the error

java.lang.IllegalStateException: Failed to load ApplicationContext
	...
	Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'okHttpClient' defined in class path resource [...]: Initialization of bean failed; nested exception is kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Unknown origin of protected open fun clone(): kotlin.Any defined in kotlin.Cloneable[SimpleFunctionDescriptorImpl@2c6aa46c] (class kotlin.reflect.jvm.internal.impl.descriptors.impl.SimpleFunctionDescriptorImpl)
	Caused by: kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Unknown origin of protected open fun clone(): kotlin.Any defined in kotlin.Cloneable[SimpleFunctionDescriptorImpl@2c6aa46c] (class kotlin.reflect.jvm.internal.impl.descriptors.impl.SimpleFunctionDescriptorImpl)

I had to also add the dependency

    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-reflect</artifactId>
      <version>1.4.0</version>
      <scope>test</scope>
    </dependency>

(kotlin-stdlib not necessary)

commonquail avatar Sep 02 '20 09:09 commonquail

I ran into a similar issue. I breaks because it embeds a copy of Kotlin 1.2 that interferes with Kotlin versions used in projects downstream in interesting ways. Results vary depending on which version is us loaded to the classpath first. I fixed it locally and will file a MR.

manuelprinz avatar Nov 21 '20 13:11 manuelprinz