Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vscode-java-test extension does not resolve correct test classpath #1427

Closed
gnoo opened this issue May 27, 2022 · 4 comments
Closed

vscode-java-test extension does not resolve correct test classpath #1427

gnoo opened this issue May 27, 2022 · 4 comments

Comments

@gnoo
Copy link

gnoo commented May 27, 2022

Java test runner extension does not resolve correct test classpath.

Vs Code Info

Version: 1.67.2
Commit: c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5
Date: 2022-05-17T18:20:57.384Z
Electron: 17.4.1
Chromium: 98.0.4758.141
Node.js: 16.13.0
V8: 9.8.177.13-electron.0
OS: Darwin x64 20.6.0

Test Runner for Java version : v0.35.0

Sample Code Repository
Please checkout to the commit tag error to reproduce the issue.

Project dependency.

> Task :dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

annotationProcessor - Annotation processors and their dependencies for source set 'main'.
No dependencies

apiElements - API elements for main. (n)
No dependencies

archives - Configuration for archive artifacts. (n)
No dependencies

compileClasspath - Compile classpath for source set 'main'.
\--- org.hibernate:hibernate-entitymanager:5.2.12.Final
     +--- org.jboss.logging:jboss-logging:3.3.0.Final
     +--- org.hibernate:hibernate-core:5.2.12.Final
     |    +--- org.jboss.logging:jboss-logging:3.3.0.Final
     |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
     |    +--- org.javassist:javassist:3.20.0-GA
     |    +--- antlr:antlr:2.7.7
     |    +--- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.1.Final
     |    +--- org.jboss:jandex:2.0.3.Final
     |    +--- com.fasterxml:classmate:1.3.0
     |    +--- dom4j:dom4j:1.6.1
     |    \--- org.hibernate.common:hibernate-commons-annotations:5.0.1.Final
     |         \--- org.jboss.logging:jboss-logging:3.3.0.Final
     +--- dom4j:dom4j:1.6.1
     +--- org.hibernate.common:hibernate-commons-annotations:5.0.1.Final (*)
     +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
     +--- org.javassist:javassist:3.20.0-GA
     +--- net.bytebuddy:byte-buddy:1.6.14
     \--- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.1.Final

compileOnly - Compile only dependencies for source set 'main'. (n)
No dependencies

default - Configuration for default artifacts. (n)
No dependencies

implementation - Implementation only dependencies for source set 'main'. (n)
\--- org.hibernate:hibernate-entitymanager:5.2.12.Final (n)

runtimeClasspath - Runtime classpath of source set 'main'.
\--- org.hibernate:hibernate-entitymanager:5.2.12.Final
     +--- org.jboss.logging:jboss-logging:3.3.0.Final
     +--- org.hibernate:hibernate-core:5.2.12.Final
     |    +--- org.jboss.logging:jboss-logging:3.3.0.Final
     |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
     |    +--- org.javassist:javassist:3.20.0-GA
     |    +--- antlr:antlr:2.7.7
     |    +--- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.1.Final
     |    +--- org.jboss:jandex:2.0.3.Final
     |    +--- com.fasterxml:classmate:1.3.0
     |    +--- dom4j:dom4j:1.6.1
     |    \--- org.hibernate.common:hibernate-commons-annotations:5.0.1.Final
     |         \--- org.jboss.logging:jboss-logging:3.3.0.Final
     +--- dom4j:dom4j:1.6.1
     +--- org.hibernate.common:hibernate-commons-annotations:5.0.1.Final (*)
     +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
     +--- org.javassist:javassist:3.20.0-GA
     +--- net.bytebuddy:byte-buddy:1.6.14
     \--- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.1.Final

runtimeElements - Elements of runtime for main. (n)
No dependencies

runtimeOnly - Runtime only dependencies for source set 'main'. (n)
No dependencies

testAnnotationProcessor - Annotation processors and their dependencies for source set 'test'.
No dependencies

testCompileClasspath - Compile classpath for source set 'test'.
+--- org.hibernate:hibernate-entitymanager:5.2.12.Final
|    +--- org.jboss.logging:jboss-logging:3.3.0.Final
|    +--- org.hibernate:hibernate-core:5.2.12.Final
|    |    +--- org.jboss.logging:jboss-logging:3.3.0.Final
|    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    +--- org.javassist:javassist:3.20.0-GA
|    |    +--- antlr:antlr:2.7.7
|    |    +--- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.1.Final
|    |    +--- org.jboss:jandex:2.0.3.Final
|    |    +--- com.fasterxml:classmate:1.3.0
|    |    +--- dom4j:dom4j:1.6.1
|    |    \--- org.hibernate.common:hibernate-commons-annotations:5.0.1.Final
|    |         \--- org.jboss.logging:jboss-logging:3.3.0.Final
|    +--- dom4j:dom4j:1.6.1
|    +--- org.hibernate.common:hibernate-commons-annotations:5.0.1.Final (*)
|    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    +--- org.javassist:javassist:3.20.0-GA
|    +--- net.bytebuddy:byte-buddy:1.6.14 -> 1.12.9
|    \--- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.1.Final
+--- junit:junit:4.13
|    \--- org.hamcrest:hamcrest-core:1.3
\--- org.mockito:mockito-inline:4.5.1
     \--- org.mockito:mockito-core:4.5.1
          +--- net.bytebuddy:byte-buddy:1.12.9
          \--- net.bytebuddy:byte-buddy-agent:1.12.9

testCompileOnly - Compile only dependencies for source set 'test'. (n)
No dependencies

testImplementation - Implementation only dependencies for source set 'test'. (n)
+--- junit:junit:4.13 (n)
\--- org.mockito:mockito-inline:4.5.1 (n)

testRuntimeClasspath - Runtime classpath of source set 'test'.
+--- org.hibernate:hibernate-entitymanager:5.2.12.Final
|    +--- org.jboss.logging:jboss-logging:3.3.0.Final
|    +--- org.hibernate:hibernate-core:5.2.12.Final
|    |    +--- org.jboss.logging:jboss-logging:3.3.0.Final
|    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    +--- org.javassist:javassist:3.20.0-GA
|    |    +--- antlr:antlr:2.7.7
|    |    +--- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.1.Final
|    |    +--- org.jboss:jandex:2.0.3.Final
|    |    +--- com.fasterxml:classmate:1.3.0
|    |    +--- dom4j:dom4j:1.6.1
|    |    \--- org.hibernate.common:hibernate-commons-annotations:5.0.1.Final
|    |         \--- org.jboss.logging:jboss-logging:3.3.0.Final
|    +--- dom4j:dom4j:1.6.1
|    +--- org.hibernate.common:hibernate-commons-annotations:5.0.1.Final (*)
|    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    +--- org.javassist:javassist:3.20.0-GA
|    +--- net.bytebuddy:byte-buddy:1.6.14 -> 1.12.9
|    \--- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.1.Final
+--- junit:junit:4.13
|    \--- org.hamcrest:hamcrest-core:1.3
\--- org.mockito:mockito-inline:4.5.1
     \--- org.mockito:mockito-core:4.5.1
          +--- net.bytebuddy:byte-buddy:1.12.9
          +--- net.bytebuddy:byte-buddy-agent:1.12.9
          \--- org.objenesis:objenesis:3.2

testRuntimeOnly - Runtime only dependencies for source set 'test'. (n)
No dependencies

(*) - dependencies omitted (listed previously)

(n) - Not resolved (configuration is not meant to be resolved)

A web-based, searchable dependency report is available by adding the --scan option.

Above is dependencies for the project. While hibernate depends on old byte-buddy version(1.6.4)(listed in runtimeClasspath), mockito depends on recent version(1.12.9) of byte-code(listed in testRuntimeClasspath). When test is executed, the recent version(1.12.9) of byte-buddy in testRuntimeClasspath should be added to classpath, but instead the extension adds old version(1.6.4) of byte-buddy and leads to exception below.

java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
 at org.mockito.internal.configuration.plugins.PluginLoader$1.invoke([PluginLoader.java:88](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.internal.configuration.plugins.PluginLoader%241.invoke(PluginLoader.java%3A88)%22%2C%22vscode-java-test-sample%22%5D))
 at com.sun.proxy.$Proxy21.isTypeMockable(Unknown Source)
 at org.mockito.internal.util.MockUtil.typeMockabilityOf([MockUtil.java:33](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java%3A33)%22%2C%22vscode-java-test-sample%22%5D))
 at org.mockito.internal.util.MockCreationValidator.validateType([MockCreationValidator.java:22](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java%3A22)%22%2C%22vscode-java-test-sample%22%5D))
 at org.mockito.internal.creation.MockSettingsImpl.validatedSettings([MockSettingsImpl.java:250](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java%3A250)%22%2C%22vscode-java-test-sample%22%5D))
 at org.mockito.internal.creation.MockSettingsImpl.build([MockSettingsImpl.java:232](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.internal.creation.MockSettingsImpl.build(MockSettingsImpl.java%3A232)%22%2C%22vscode-java-test-sample%22%5D))
 at org.mockito.internal.MockitoCore.mock([MockitoCore.java:94](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.internal.MockitoCore.mock(MockitoCore.java%3A94)%22%2C%22vscode-java-test-sample%22%5D))
 at org.mockito.Mockito.mock([Mockito.java:1965](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.Mockito.mock(Mockito.java%3A1965)%22%2C%22vscode-java-test-sample%22%5D))
 at org.mockito.Mockito.mock([Mockito.java:1880](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.Mockito.mock(Mockito.java%3A1880)%22%2C%22vscode-java-test-sample%22%5D))
 at vscode.java.test.sample.AppTest.sampleTest([AppTest.java:12](command:_java.test.openStackTrace?%5B%22%5Ctat%20vscode.java.test.sample.AppTest.sampleTest(AppTest.java%3A12)%22%2C%22vscode-java-test-sample%22%5D))
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in sun.misc.CompoundEnumeration@23a5fd2
 at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl([PluginInitializer.java:58](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java%3A58)%22%2C%22vscode-java-test-sample%22%5D))
 at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin([PluginLoader.java:69](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java%3A69)%22%2C%22vscode-java-test-sample%22%5D))
 at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin([PluginLoader.java:54](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java%3A54)%22%2C%22vscode-java-test-sample%22%5D))
 at org.mockito.internal.configuration.plugins.PluginRegistry.([PluginRegistry.java:28](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.internal.configuration.plugins.PluginRegistry.%3Cinit%3E(PluginRegistry.java%3A28)%22%2C%22vscode-java-test-sample%22%5D))
 at org.mockito.internal.configuration.plugins.Plugins.([Plugins.java:22](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.internal.configuration.plugins.Plugins.%3Cclinit%3E(Plugins.java%3A22)%22%2C%22vscode-java-test-sample%22%5D))
 at org.mockito.internal.MockitoCore.([MockitoCore.java:77](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.internal.MockitoCore.%3Cclinit%3E(MockitoCore.java%3A77)%22%2C%22vscode-java-test-sample%22%5D))
 at org.mockito.Mockito.([Mockito.java:1614](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.Mockito.%3Cclinit%3E(Mockito.java%3A1614)%22%2C%22vscode-java-test-sample%22%5D))
 ... 27 more
Caused by: java.lang.reflect.InvocationTargetException
 at java.lang.reflect.Constructor.newInstance([Constructor.java:423](command:_java.test.openStackTrace?%5B%22%5Ctat%20java.lang.reflect.Constructor.newInstance(Constructor.java%3A423)%22%2C%22vscode-java-test-sample%22%5D))
 at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl([PluginInitializer.java:53](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java%3A53)%22%2C%22vscode-java-test-sample%22%5D))
 ... 33 more
Caused by: java.lang.NoSuchMethodError: net.bytebuddy.asm.AsmVisitorWrapper$ForDeclaredMethods.constructor(Lnet/bytebuddy/matcher/ElementMatcher;[Lnet/bytebuddy/asm/AsmVisitorWrapper$ForDeclaredMethods$MethodVisitorWrapper;)Lnet/bytebuddy/asm/AsmVisitorWrapper$ForDeclaredMethods;
 at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.([InlineBytecodeGenerator.java:136](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.%3Cinit%3E(InlineBytecodeGenerator.java%3A136)%22%2C%22vscode-java-test-sample%22%5D))
 at org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker.([InlineDelegateByteBuddyMockMaker.java:315](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker.%3Cinit%3E(InlineDelegateByteBuddyMockMaker.java%3A315)%22%2C%22vscode-java-test-sample%22%5D))
 at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.([InlineByteBuddyMockMaker.java:23](command:_java.test.openStackTrace?%5B%22%5Ctat%20org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.%3Cinit%3E(InlineByteBuddyMockMaker.java%3A23)%22%2C%22vscode-java-test-sample%22%5D))
 ... 38 more

The test works correctly if a recent version of byte-buddy is added to runtimeClasspath(not testRuntimeClasspath) with implementation configuration. Please check working commit tag for working sample. Thanks.

@jdneo
Copy link
Member

jdneo commented May 29, 2022

Maybe this is the same root cause as #1045.

@gnoo
Copy link
Author

gnoo commented Jun 2, 2022

@jdneo yes, it is the same cause as #1045. Any schedule on delegate to gradle feature?

@jdneo
Copy link
Member

jdneo commented Jun 4, 2022

Let's tracked it via #1045. (You can vote there)

So far, it's still in our backlog.

@jdneo jdneo closed this as completed Jun 4, 2022
@jdneo jdneo added the duplicate label Jun 4, 2022
@jdneo
Copy link
Member

jdneo commented Aug 5, 2024

The Gradle Test Delegation (both run and debug) has supported now.

To use this feature, you need to install the latest Test Runner for Java and Gradle for Java extension.

To delegate the tests to Gradle, you can set the default testing profile in Testing explorer:
image
image

If you do not want to change the default testing profile, you can trigger an one-time execution via:
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants