Hello,
Please consider the following test (using MockK):
class MockkSpec : Spek({
val mock = mockk<Greeter>()
beforeEachTest {
every { mock.greet(any()) } answers { "Hello ${args[0]}" }
}
afterEachTest {
clearMocks(mock)
}
describe("greet(\"mock\")") {
val result by memoized { mock.greet("mock") }
it("should return \"Hello mock\"") {
assertEquals("Hello mock", result)
}
}
})
It runs fine from gradle (graldew test). But running the test from IntelliJ fails with:
Exception in thread "main" java.lang.NoClassDefFoundError: io/mockk/proxy/jvm/dispatcher/JvmMockKDispatcher
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:801)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:699)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:622)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:801)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:699)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:622)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at io.mockk.proxy.jvm.transformation.SubclassInstrumentation$AdviceBuilder.build(SubclassInstrumentation.kt:28)
at io.mockk.proxy.jvm.transformation.SubclassInstrumentation.<init>(SubclassInstrumentation.kt:33)
at io.mockk.proxy.jvm.JvmMockKAgentFactory$init$Initializer.init(JvmMockKAgentFactory.kt:92)
at io.mockk.proxy.jvm.JvmMockKAgentFactory.init(JvmMockKAgentFactory.kt:123)
at io.mockk.impl.JvmMockKGateway.<init>(JvmMockKGateway.kt:46)
at io.mockk.impl.JvmMockKGateway.<clinit>(JvmMockKGateway.kt:169)
at playground.MockkSpec$1.invoke(MockkSpec.kt:37)
at playground.MockkSpec$1.invoke(MockkSpec.kt:11)
at org.spekframework.spek2.runtime.AbstractRuntime.resolveSpec(SpekRuntime.kt:27)
at org.spekframework.spek2.runtime.SpekRuntime.discover(SpekJvmRuntime.kt:35)
at org.spekframework.ide.Spek2ConsoleLauncher.run(console.kt:21)
at org.spekframework.ide.ConsoleKt$main$1.invoke(console.kt:34)
at org.spekframework.ide.ConsoleKt$main$1.invoke(console.kt)
at shadow.com.xenomachina.argparser.SystemExitExceptionKt.mainBody(SystemExitException.kt:74)
at shadow.com.xenomachina.argparser.SystemExitExceptionKt.mainBody$default(SystemExitException.kt:72)
at org.spekframework.ide.ConsoleKt.main(console.kt:32)
Caused by: java.lang.ClassNotFoundException: io.mockk.proxy.jvm.dispatcher.JvmMockKDispatcher
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 34 more
Please also note that it doesn't concern only Mockk. Using Mockito also fail:
Exception in thread "main" 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:74)
at com.sun.proxy.$Proxy2.isTypeMockable(Unknown Source)
at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:29)
at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:238)
at org.mockito.internal.creation.MockSettingsImpl.build(MockSettingsImpl.java:226)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:68)
at org.mockito.Mockito.mock(Mockito.java:1896)
at org.mockito.Mockito.mock(Mockito.java:1805)
at playground.MockitoSpec$1.invoke(MockitoSpec.kt:11)
at playground.MockitoSpec$1.invoke(MockitoSpec.kt:10)
at org.spekframework.spek2.runtime.AbstractRuntime.resolveSpec(SpekRuntime.kt:27)
at org.spekframework.spek2.runtime.SpekRuntime.discover(SpekJvmRuntime.kt:35)
at org.spekframework.ide.Spek2ConsoleLauncher.run(console.kt:21)
at org.spekframework.ide.ConsoleKt$main$1.invoke(console.kt:34)
at org.spekframework.ide.ConsoleKt$main$1.invoke(console.kt)
at shadow.com.xenomachina.argparser.SystemExitExceptionKt.mainBody(SystemExitException.kt:74)
at shadow.com.xenomachina.argparser.SystemExitExceptionKt.mainBody$default(SystemExitException.kt:72)
at org.spekframework.ide.ConsoleKt.main(console.kt:32)
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in java.lang.CompoundEnumeration@21129f1f
at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:54)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:57)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:44)
at org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:21)
at org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:18)
at org.mockito.internal.util.MockUtil.<clinit>(MockUtil.java:24)
... 16 more
Caused by: org.mockito.exceptions.base.MockitoInitializationException:
Could not initialize inline Byte Buddy mock maker. (This mock maker is not supported on Android.)
And finally also note that running the Junit5 equivalents works just fine, even when triggered from IntellIJ.
That's weird, I've used both libraries and seem to work fine for me. Can you share your build script? Or better yet a sample project reproduces the issue?
Can you share your build script? Or better yet a sample project reproduces the issue?
Sure.
Here is a project allowing to reproduce the problem consistently: https://github.com/jcornaz/spek-mock-bug
Again, don't run gradlew test it would work just fine. My problem is about running from IntelliJ.
Steps to reproduce
MockkSpec

Project JDK
1.8.0_162
IntelliJ
IntelliJ IDEA 2018.3.3 (Ultimate Edition)
Build #IU-183.5153.38, built on January 9, 2019
JRE: 1.8.0_152-release-1343-b26 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
Kotlin plugin
1.3.11-release-IJ2018.3-1
Spek Framework plugin
v2.0.0-rc.1.167+0914c41-IJ2018.3
With the hope it helps, here are more information I've found:
MockitoSpec behaves as expected.testCompile("org.koin:koin-test:2.0.0-alpha-6") to build.gradle.kts will make MockitoSpec fail.exclude(group = "org.mockito") to the koin-test dependency solves the problem, and MockitoSpec pass again.exclude(group = "org.mockito") and downgrading Mockito to 2.21.0 (in order to have same version than the one declared by koin-test) makes MockitoSpec failing. But this time there isn't any dependency conflict.mockk and its dependencies (objenesis 2.6 and bytebuddy 1.9.3).1.3.0 (standard and reflection libraries) while I use Kotlin 1.3.11.@jcornaz I cloned the project, tried running the tests via gradle and intellij - everything passed. Adding estCompile("org.koin:koin-test:2.0.0-alpha-6") does not make a difference - tests still passed. It works for JDK 10 and JDK 8 for me - so it's not a java version problem.
But we consistently reproduce the problem on 3 different machines and 3 different projects.
Are you on Windows? Did you use the same IntelliJ version? Did you use the gutter icon in IntelliJ?
My windows is not setup for development. I have the same version of IJ and the spek plugin. Looking back at the main post, this looks interesting: This mock maker is not supported on Android..
Also make sure to untick "Delegate IDE build/run actions to gradle"

This mock maker is not supported on Android.
None of our projects are Android projects. So it is definitely not the problem.
P.S: And it would concern only Mockito, not MockK anyway.
EDIT: This message has been moved to a separate issue: #568
@jcornaz Can you file that as a separate issue?
This mock maker is not supported on Android.
Weird, have you reported to the mockito team?
Also make sure to untick "Delegate IDE build/run actions to gradle"
I don't have it unticked.
Can you run ./gradlew dependencies and paste the output here?
This mock maker is not supported on Android.
Weird, have you reported to the mocking team?
No because:
My point is: Don't look too much in that direction. Since the problem is reproducible in non-android projects, it is very unlikely that there is any correlation between this message and the bug reported here.
Also make sure to untick "Delegate IDE build/run actions to gradle"
I don't have it unticked.
So that's why you don't reproduce the problem. Untick it, and you should be able to reproduce it.
Please let me add that we need to untick that box in at least one of our project, which is a maven project and for which delegating to maven is really too slow.
Can you run ./gradlew dependencies and paste the output here?
> Task :dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
annotationProcessor - Annotation processors and their dependencies for source set 'main'.
No dependencies
api - API dependencies for compilation 'main' (target (jvm)). (n)
No dependencies
apiDependenciesMetadata
\--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:{prefer 1.3.11} -> 1.3.11
+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11
| +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| \--- org.jetbrains:annotations:13.0
\--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11
\--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
apiElements - API elements for main. (n)
No dependencies
archives - Configuration for archive artifacts.
No dependencies
compile - Dependencies for compilation 'main' (target (jvm)) (deprecated, use 'implementation ' instead).
\--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:{prefer 1.3.11} -> 1.3.11
+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11
| +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| \--- org.jetbrains:annotations:13.0
\--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11
\--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
compileClasspath - Compile classpath for compilation 'main' (target (jvm)).
\--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:{prefer 1.3.11} -> 1.3.11
+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11
| +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| \--- org.jetbrains:annotations:13.0
\--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11
\--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
compileOnly - Compile only dependencies for compilation 'main' (target (jvm)).
No dependencies
compileOnlyDependenciesMetadata
No dependencies
default - Configuration for default artifacts.
\--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:{prefer 1.3.11} -> 1.3.11
+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11
| +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| \--- org.jetbrains:annotations:13.0
\--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11
\--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
implementation - Implementation only dependencies for compilation 'main' (target (jvm)). (n)
No dependencies
implementationDependenciesMetadata
\--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:{prefer 1.3.11} -> 1.3.11
+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11
| +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| \--- org.jetbrains:annotations:13.0
\--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11
\--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
kapt
No dependencies
kaptTest
No dependencies
kotlinCompilerClasspath
\--- org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.11
+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11
| +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| \--- org.jetbrains:annotations:13.0
+--- org.jetbrains.kotlin:kotlin-script-runtime:1.3.11
\--- org.jetbrains.kotlin:kotlin-reflect:1.3.11
\--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
kotlinCompilerPluginClasspath
\--- org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.3.11
kotlinNativeCompilerPluginClasspath
No dependencies
kotlinScriptDef
No dependencies
runtime - Runtime dependencies for compilation 'main' (target (jvm)) (deprecated, use 'runtimeOnly ' instead).
\--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:{prefer 1.3.11} -> 1.3.11
+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11
| +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| \--- org.jetbrains:annotations:13.0
\--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11
\--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
runtimeClasspath - Runtime classpath of compilation 'main' (target (jvm)).
\--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:{prefer 1.3.11} -> 1.3.11
+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11
| +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| \--- org.jetbrains:annotations:13.0
\--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11
\--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
runtimeElements - Elements of runtime for main. (n)
No dependencies
runtimeOnly - Runtime only dependencies for compilation 'main' (target (jvm)). (n)
No dependencies
runtimeOnlyDependenciesMetadata
No dependencies
testAnnotationProcessor - Annotation processors and their dependencies for source set 'test'.
No dependencies
testApi - API dependencies for compilation 'test' (target (jvm)). (n)
No dependencies
testApiDependenciesMetadata
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:{prefer 1.3.11} -> 1.3.11
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11
| | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| | \--- org.jetbrains:annotations:13.0
| \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
+--- org.jetbrains.kotlin:kotlin-test:{prefer 1.3.11} -> 1.3.11
| +--- org.jetbrains.kotlin:kotlin-test-common:1.3.11
| | \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
+--- io.mockk:mockk:1.9
| +--- io.mockk:mockk-common:1.9
| | \--- io.mockk:mockk-dsl:1.9
| +--- io.mockk:mockk-dsl-jvm:1.9
| | +--- io.mockk:mockk-dsl:1.9
| | \--- org.jetbrains.kotlin:kotlin-reflect:1.3.0
| | \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.0 -> 1.3.11 (*)
| +--- io.mockk:mockk-agent-jvm:1.9
| | +--- io.mockk:mockk-agent-api:1.9
| | +--- io.mockk:mockk-agent-common:1.9
| | | \--- io.mockk:mockk-agent-api:1.9
| | +--- org.objenesis:objenesis:2.6
| | +--- net.bytebuddy:byte-buddy:1.9.3
| | \--- net.bytebuddy:byte-buddy-agent:1.9.3
| \--- org.jetbrains.kotlin:kotlin-reflect:1.3.0 (*)
+--- org.mockito:mockito-core:2.23.4
| +--- net.bytebuddy:byte-buddy:1.9.3
| +--- net.bytebuddy:byte-buddy-agent:1.9.3
| \--- org.objenesis:objenesis:2.6
+--- org.junit.jupiter:junit-jupiter-api:5.3.2
| +--- org.apiguardian:apiguardian-api:1.0.0
| +--- org.opentest4j:opentest4j:1.1.1
| \--- org.junit.platform:junit-platform-commons:1.3.2
| \--- org.apiguardian:apiguardian-api:1.0.0
\--- org.spekframework.spek2:spek-dsl-jvm:2.0.0-rc.1
\--- org.spekframework.spek2:spek-dsl-common:2.0.0-rc.1
testCompile - Dependencies for compilation 'test' (target (jvm)) (deprecated, use 'testImplementation ' instead).
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:{prefer 1.3.11} -> 1.3.11
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11
| | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| | \--- org.jetbrains:annotations:13.0
| \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
+--- org.jetbrains.kotlin:kotlin-test:{prefer 1.3.11} -> 1.3.11
| +--- org.jetbrains.kotlin:kotlin-test-common:1.3.11
| | \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
+--- io.mockk:mockk:1.9
| +--- io.mockk:mockk-common:1.9
| | \--- io.mockk:mockk-dsl:1.9
| +--- io.mockk:mockk-dsl-jvm:1.9
| | +--- io.mockk:mockk-dsl:1.9
| | \--- org.jetbrains.kotlin:kotlin-reflect:1.3.0
| | \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.0 -> 1.3.11 (*)
| +--- io.mockk:mockk-agent-jvm:1.9
| | +--- io.mockk:mockk-agent-api:1.9
| | +--- io.mockk:mockk-agent-common:1.9
| | | \--- io.mockk:mockk-agent-api:1.9
| | +--- org.objenesis:objenesis:2.6
| | +--- net.bytebuddy:byte-buddy:1.9.3
| | \--- net.bytebuddy:byte-buddy-agent:1.9.3
| \--- org.jetbrains.kotlin:kotlin-reflect:1.3.0 (*)
+--- org.mockito:mockito-core:2.23.4
| +--- net.bytebuddy:byte-buddy:1.9.3
| +--- net.bytebuddy:byte-buddy-agent:1.9.3
| \--- org.objenesis:objenesis:2.6
+--- org.junit.jupiter:junit-jupiter-api:5.3.2
| +--- org.apiguardian:apiguardian-api:1.0.0
| +--- org.opentest4j:opentest4j:1.1.1
| \--- org.junit.platform:junit-platform-commons:1.3.2
| \--- org.apiguardian:apiguardian-api:1.0.0
\--- org.spekframework.spek2:spek-dsl-jvm:2.0.0-rc.1
\--- org.spekframework.spek2:spek-dsl-common:2.0.0-rc.1
testCompileClasspath - Compile classpath for compilation 'test' (target (jvm)).
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:{prefer 1.3.11} -> 1.3.11
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11
| | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| | \--- org.jetbrains:annotations:13.0
| \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
+--- org.jetbrains.kotlin:kotlin-test:{prefer 1.3.11} -> 1.3.11
| +--- org.jetbrains.kotlin:kotlin-test-common:1.3.11
| | \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
+--- io.mockk:mockk:1.9
| +--- io.mockk:mockk-common:1.9
| | \--- io.mockk:mockk-dsl:1.9
| +--- io.mockk:mockk-dsl-jvm:1.9
| | +--- io.mockk:mockk-dsl:1.9
| | \--- org.jetbrains.kotlin:kotlin-reflect:1.3.0
| | \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.0 -> 1.3.11 (*)
| +--- io.mockk:mockk-agent-jvm:1.9
| | +--- io.mockk:mockk-agent-api:1.9
| | +--- io.mockk:mockk-agent-common:1.9
| | | \--- io.mockk:mockk-agent-api:1.9
| | +--- org.objenesis:objenesis:2.6
| | +--- net.bytebuddy:byte-buddy:1.9.3
| | \--- net.bytebuddy:byte-buddy-agent:1.9.3
| \--- org.jetbrains.kotlin:kotlin-reflect:1.3.0 (*)
+--- org.mockito:mockito-core:2.23.4
| +--- net.bytebuddy:byte-buddy:1.9.3
| +--- net.bytebuddy:byte-buddy-agent:1.9.3
| \--- org.objenesis:objenesis:2.6
+--- org.junit.jupiter:junit-jupiter-api:5.3.2
| +--- org.apiguardian:apiguardian-api:1.0.0
| +--- org.opentest4j:opentest4j:1.1.1
| \--- org.junit.platform:junit-platform-commons:1.3.2
| \--- org.apiguardian:apiguardian-api:1.0.0
\--- org.spekframework.spek2:spek-dsl-jvm:2.0.0-rc.1
\--- org.spekframework.spek2:spek-dsl-common:2.0.0-rc.1
testCompileOnly - Compile only dependencies for compilation 'test' (target (jvm)).
No dependencies
testCompileOnlyDependenciesMetadata
No dependencies
testImplementation - Implementation only dependencies for compilation 'test' (target (jvm)). (n)
No dependencies
testImplementationDependenciesMetadata
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:{prefer 1.3.11} -> 1.3.11
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11
| | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| | \--- org.jetbrains:annotations:13.0
| \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
+--- org.jetbrains.kotlin:kotlin-test:{prefer 1.3.11} -> 1.3.11
| +--- org.jetbrains.kotlin:kotlin-test-common:1.3.11
| | \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
+--- io.mockk:mockk:1.9
| +--- io.mockk:mockk-common:1.9
| | \--- io.mockk:mockk-dsl:1.9
| +--- io.mockk:mockk-dsl-jvm:1.9
| | +--- io.mockk:mockk-dsl:1.9
| | \--- org.jetbrains.kotlin:kotlin-reflect:1.3.0
| | \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.0 -> 1.3.11 (*)
| +--- io.mockk:mockk-agent-jvm:1.9
| | +--- io.mockk:mockk-agent-api:1.9
| | +--- io.mockk:mockk-agent-common:1.9
| | | \--- io.mockk:mockk-agent-api:1.9
| | +--- org.objenesis:objenesis:2.6
| | +--- net.bytebuddy:byte-buddy:1.9.3
| | \--- net.bytebuddy:byte-buddy-agent:1.9.3
| \--- org.jetbrains.kotlin:kotlin-reflect:1.3.0 (*)
+--- org.mockito:mockito-core:2.23.4
| +--- net.bytebuddy:byte-buddy:1.9.3
| +--- net.bytebuddy:byte-buddy-agent:1.9.3
| \--- org.objenesis:objenesis:2.6
+--- org.junit.jupiter:junit-jupiter-api:5.3.2
| +--- org.apiguardian:apiguardian-api:1.0.0
| +--- org.opentest4j:opentest4j:1.1.1
| \--- org.junit.platform:junit-platform-commons:1.3.2
| \--- org.apiguardian:apiguardian-api:1.0.0
\--- org.spekframework.spek2:spek-dsl-jvm:2.0.0-rc.1
\--- org.spekframework.spek2:spek-dsl-common:2.0.0-rc.1
testKotlinScriptDef
No dependencies
testRuntime - Runtime dependencies for compilation 'test' (target (jvm)) (deprecated, use 'testRuntimeOnly ' instead).
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:{prefer 1.3.11} -> 1.3.11
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11
| | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| | \--- org.jetbrains:annotations:13.0
| \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
+--- org.jetbrains.kotlin:kotlin-test:{prefer 1.3.11} -> 1.3.11
| +--- org.jetbrains.kotlin:kotlin-test-common:1.3.11
| | \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
+--- io.mockk:mockk:1.9
| +--- io.mockk:mockk-common:1.9
| | \--- io.mockk:mockk-dsl:1.9
| +--- io.mockk:mockk-dsl-jvm:1.9
| | +--- io.mockk:mockk-dsl:1.9
| | \--- org.jetbrains.kotlin:kotlin-reflect:1.3.0
| | \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.0 -> 1.3.11 (*)
| +--- io.mockk:mockk-agent-jvm:1.9
| | +--- io.mockk:mockk-agent-api:1.9
| | +--- io.mockk:mockk-agent-common:1.9
| | | \--- io.mockk:mockk-agent-api:1.9
| | +--- org.objenesis:objenesis:2.6
| | +--- net.bytebuddy:byte-buddy:1.9.3
| | \--- net.bytebuddy:byte-buddy-agent:1.9.3
| \--- org.jetbrains.kotlin:kotlin-reflect:1.3.0 (*)
+--- org.mockito:mockito-core:2.23.4
| +--- net.bytebuddy:byte-buddy:1.9.3
| +--- net.bytebuddy:byte-buddy-agent:1.9.3
| \--- org.objenesis:objenesis:2.6
+--- org.junit.jupiter:junit-jupiter-api:5.3.2
| +--- org.apiguardian:apiguardian-api:1.0.0
| +--- org.opentest4j:opentest4j:1.1.1
| \--- org.junit.platform:junit-platform-commons:1.3.2
| \--- org.apiguardian:apiguardian-api:1.0.0
+--- org.spekframework.spek2:spek-dsl-jvm:2.0.0-rc.1
| \--- org.spekframework.spek2:spek-dsl-common:2.0.0-rc.1
\--- org.junit.jupiter:junit-jupiter-engine:5.3.2
+--- org.apiguardian:apiguardian-api:1.0.0
+--- org.junit.platform:junit-platform-engine:1.3.2
| +--- org.apiguardian:apiguardian-api:1.0.0
| +--- org.junit.platform:junit-platform-commons:1.3.2 (*)
| \--- org.opentest4j:opentest4j:1.1.1
\--- org.junit.jupiter:junit-jupiter-api:5.3.2 (*)
testRuntimeClasspath - Runtime classpath of compilation 'test' (target (jvm)).
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:{prefer 1.3.11} -> 1.3.11
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11
| | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| | \--- org.jetbrains:annotations:13.0
| \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
+--- org.jetbrains.kotlin:kotlin-test:{prefer 1.3.11} -> 1.3.11
| +--- org.jetbrains.kotlin:kotlin-test-common:1.3.11
| | \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
+--- io.mockk:mockk:1.9
| +--- io.mockk:mockk-common:1.9
| | \--- io.mockk:mockk-dsl:1.9
| +--- io.mockk:mockk-dsl-jvm:1.9
| | +--- io.mockk:mockk-dsl:1.9
| | \--- org.jetbrains.kotlin:kotlin-reflect:1.3.0
| | \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.0 -> 1.3.11 (*)
| +--- io.mockk:mockk-agent-jvm:1.9
| | +--- io.mockk:mockk-agent-api:1.9
| | +--- io.mockk:mockk-agent-common:1.9
| | | \--- io.mockk:mockk-agent-api:1.9
| | +--- org.objenesis:objenesis:2.6
| | +--- net.bytebuddy:byte-buddy:1.9.3
| | \--- net.bytebuddy:byte-buddy-agent:1.9.3
| \--- org.jetbrains.kotlin:kotlin-reflect:1.3.0 (*)
+--- org.mockito:mockito-core:2.23.4
| +--- net.bytebuddy:byte-buddy:1.9.3
| +--- net.bytebuddy:byte-buddy-agent:1.9.3
| \--- org.objenesis:objenesis:2.6
+--- org.junit.jupiter:junit-jupiter-api:5.3.2
| +--- org.apiguardian:apiguardian-api:1.0.0
| +--- org.opentest4j:opentest4j:1.1.1
| \--- org.junit.platform:junit-platform-commons:1.3.2
| \--- org.apiguardian:apiguardian-api:1.0.0
+--- org.spekframework.spek2:spek-dsl-jvm:2.0.0-rc.1
| \--- org.spekframework.spek2:spek-dsl-common:2.0.0-rc.1
+--- org.junit.jupiter:junit-jupiter-engine:5.3.2
| +--- org.apiguardian:apiguardian-api:1.0.0
| +--- org.junit.platform:junit-platform-engine:1.3.2
| | +--- org.apiguardian:apiguardian-api:1.0.0
| | +--- org.junit.platform:junit-platform-commons:1.3.2 (*)
| | \--- org.opentest4j:opentest4j:1.1.1
| \--- org.junit.jupiter:junit-jupiter-api:5.3.2 (*)
\--- org.spekframework.spek2:spek-runner-junit5:2.0.0-rc.1
\--- org.spekframework.spek2:spek-runtime-jvm:2.0.0-rc.1
+--- org.spekframework.spek2:spek-runtime-common:2.0.0-rc.1
| \--- org.spekframework.spek2:spek-dsl-common:2.0.0-rc.1
+--- org.spekframework.spek2:spek-dsl-jvm:2.0.0-rc.1 (*)
\--- io.github.classgraph:classgraph:4.0.6
testRuntimeOnly - Runtime only dependencies for compilation 'test' (target (jvm)). (n)
\--- org.spekframework.spek2:spek-runner-junit5:2.0.0-rc.1 (n)
testRuntimeOnlyDependenciesMetadata
\--- org.spekframework.spek2:spek-runner-junit5:2.0.0-rc.1
\--- org.spekframework.spek2:spek-runtime-jvm:2.0.0-rc.1
+--- org.spekframework.spek2:spek-runtime-common:2.0.0-rc.1
| \--- org.spekframework.spek2:spek-dsl-common:2.0.0-rc.1
\--- org.spekframework.spek2:spek-dsl-jvm:2.0.0-rc.1
\--- org.spekframework.spek2:spek-dsl-common:2.0.0-rc.1
(*) - 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.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 2s
1 actionable task: 1 executed
Oops sorry double negatives. I don't have it ticked.
Is there a difference between running the tests from the IJ and gradle?
Is there a difference between running the tests from the IJ and gradle?
Yes. From gradle it works as expected. Not from IJ.
Please notice that running all test from IJ also works as expected. Only running from the gutter icon does not work.
Interesting, it may be a problem with your IJ setup. Have you tried re-installing the spek plugin? If that doesn't work can you test with a vanilla IJ + spek plugin only (it may be conflicting with some other plugin)?
Have you tried re-installing the spek plugin?
No. But since we reproduce the problem on 3 different installations, I really doubt that it would make any difference. I will try however.
can you test with a vanilla IJ + spek plugin only (it may be conflicting with some other plugin)?
I will try and keep you updated.
EDIT: Disabling all downloaded plugins (except Kotlin and Spekframework) didn't help
I just cloned your bug-repository and ran the tests via the different methods successfully on
Might be related to Windows only then?!
Might be related to Windows only then?!
That's our best hypothesis I guess... I wonder how it could be related to the operating system, but I have no better clue.
I just tried with a vanilla IJ + Spekframework plugin. And I still reproduce the bug:
It does seem related to the operating system. I am not able to reproduce the bug on a Linux VM.
I can confirm the current findings: The issue with running the spec from the gutter icon seems to be an issue with Windows as OS - as opposed to Linux in my case, where the test runs without issue.
I have almost exactly the same environment as @jcornaz (except for a newer jdk):
Project JDK
1.8.0_192
IntelliJ
IntelliJ IDEA 2018.3.3 (Ultimate Edition)
Build #IU-183.5153.38, built on January 9, 2019
JRE: 1.8.0_152-release-1343-b26 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
Kotlin plugin
1.3.11-release-IJ2018.3-1
Spek Framework plugin
v2.0.0-rc.1.167+0914c41-IJ2018.3
Project JDK
jdk8-openjdk 8.u192-1 (archlinux)
IntelliJ
IntelliJ IDEA 2018.3.3 (Ultimate Edition)
Build #IU-183.5153.38, built on January 9, 2019
JRE: 1.8.0_152-release-1343-b26 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.20.1-arch1-1-ARCH
Kotlin plugin
v1.3.11-release-IJ2018.3-1
Spek Framework plugin
v2.0.0-rc.1.167+0914c41-IJ2018.3
In the run configuration, add the following VM option:
-Djava.io.tmpdir=C:\Users\<User>\AppData\Local\Temp\
@jcornaz @raniejade I believe I may have found the root cause of this issue.
Apologies in advance for the long post; I've been banging my head against this for what feels like forever.
C:\Users\<User>\AppData\Local\Temp\ is supposed to be the default value of java.io.tmpdir on Windows, but for some reason when running Spek from IntelliJ that property is set to C:\WINDOWS\ instead.
import io.mockk.mockk
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
object SpekSpec : Spek(
{
describe("A simple specification") {
println(System.getProperty("java.io.tmpdir"))
mockk<Any>()
}
}
)
C:\WINDOWS\ should be printed to the terminal. C:\Users\<User>\AppData\Local\Temp\ is printed instead, and no exception is thrown.MockK uses File.createTempFile(), which in turn uses java.io.tmpfile, to create a temporary jar file that (I believe) is loaded into the classpath. MockK expects this jar to be available when it starts mocking things.
When trying to create a temporary file in the WINDOWS directory, an IOException is thrown with an "Access Denied" message which is silently swallowed by MockK (you have to enable TRACE logging to see the warning).
Later, when MockK needs to use a class from that jar (specifically, JvmMockKDispatcher) the jar obviously isn't there, thus the NoClassDefFoundError.
I don't know if this is something that can be fixed from the Spek plugin or not, but I'll poke around a bit more now that I know what to look for.
I can confirm that the workaround of adding -Djava.io.tmpdir=C:\Users\<User>\AppData\Local\Temp\ to the VM options of the launch configuration works around the issue. Thanks @floralvikings for nailing this down.
I tried to set the parameter in the custom vm options, in order to not have to set it in the various launch configurations. It didn't work though. I guess the issue (hopefully) taken care of in https://github.com/spekframework/spek/pull/577 overrides that setting.
@ursjoss @floralvikings @jcornaz Have you looked in the console (within IJ) what paremeters IJ is passing to the jvm when running the tests? I suspect something passed there overrides the tmp dir property.
@raniejade I don't see any obvious override in the console. Do you think that #577 would not solve the issue?
By the way: Adding -Djava.io.tmpdir=C:\Users\<User>\AppData\Local\Temp\ to the VM Options of the Spek 2 - JVM template makes a nice and workable workaround for the time being.
@ursjoss #577 does not fix this issue; it fixes two other bugs that I found incidentally while looking for the root cause of this one. Sorry for the confusion
This is interesting: https://stackoverflow.com/a/29716813.
The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:
- The path specified by the TMP environment variable.
- The path specified by the TEMP environment variable.
- The path specified by the USERPROFILE environment variable.
- The Windows directory.
Looking at this, MockK writes the jar in a java agent - which may not see the env variables?
I experimented a bit more.
In analogy to @floralvikings comment 7 days ago, I created the following two classes (in two separate packages, that I left out here):
TmpSpec:
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
object TmpSpec: Spek({
describe("A simple specification") {
println("Spek: ${System.getProperty("java.io.tmpdir")}")
println()
}
})
TmpTest:
import org.junit.Test
class TmpTest {
@Test
fun printTemp() {
println("Junit: ${System.getProperty("java.io.tmpdir")}")
println()
}
}
Not surprisingly the JUnitTest prints the expected temp path (Junit: C:\Users\UrsJoss\AppData\Local\Temp)
Running the Spek variant produced different outcomes, depending on how I triggered the test.
Spek: C:\WINDOWS\, which would result in MockK not being able to store the temporary jars due to missing permission of my user to write to that directory.Presumably on the command line the TMP environment variable can be accessed correctly while this seems not be the case from within the spek runner in IntelliJ.
Comparing the two commands running TmpSpec ( (a) right click on package and (b) from gutter icon ) illustrated a few differences that may be noteworthy:
-ea and -Didea.test.cyclic.buffer.size=1048576. (b) misses those but adds interop-jvm-2.0.0-rc.1.180+b8533a4-all.jar as last element of the classpath.JunitStarter -ideVersion5 -junit5 ... -socket...ConsoleKt --sourceDirs .. --paths ...junit5 option in (a) explicitly sets the temp dirs. The last part of the entire command (after class path, starting with the executed class):com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit5 @w@C:\Users\UrsJoss\AppData\Local\Temp\idea_working_dirs_junit.tmp @C:\Users\UrsJoss\AppData\Local\Temp\idea_junit.tmp -socket57805
Maybe the spek runner should also add the temp path explicitly.
@ursjoss wow, thanks for a detailed investigation! Spek is definitely doing something different.
The parameters passed to the junit5 option in (a) explicitly sets the temp dirs. The last part of the entire command (after class path, starting with the executed class):
It's not setting the path here, @c and @w@ are parameters required by JunitStarter - it just happens that they are using the temp directory.
@ursjoss do you have this option ticked for the spek run configuration?

JUnit by default has it enabled!
do you have this option ticked for the spek run configuration?
Indeed it it ticked by default for Junit but not for Spek.
Junit:

Spek:

does ticking it fix the problem?
does ticking it fix the problem?
Yes!
:tada: fix is a one liner :joy:. Anyway, in the meantime you can set the default for Spek 2 - JVM template via the ui.
Excellent, thank you @raniejade.
Awesome! I was so close to figuring it out too, didn't even think of looking at that field 馃槥
Thanks for the awesome research and quick turnaround @ursjoss and @raniejade!
馃帀 fix is a one liner 馃槀. Anyway, in the meantime you can set the default for Spek 2 - JVM template via the ui.
There is also an effort from the MockK team to fix this issue https://github.com/mockk/mockk/issues/239
Most helpful comment
:tada: fix is a one liner :joy:. Anyway, in the meantime you can set the default for Spek 2 - JVM template via the ui.