Hey. I’ve been using Spek for a year and pretty ha...
# spek
d
Hey. I’ve been using Spek for a year and pretty happy with it. Recently we started migration to Spek 2 and faced several issues. 1. ⚠️ Our tests are green if we run them from Android Studio, but ≈80% of them become red if we run tests from Gradle. We get lots of `java.lang.VerifyError`s. Therefore we can’t gather jaCoCo coverage. 2. To be able to run tests from IDE we have to annotate speks with
@RunWith(JUnitPlatform::class)
but it requires us to change kotlin dependency from
kotlin-stdlib-jdk7
to
kotlin-stdlib-jdk8
because it needs streams. Any advice? spek 2.0.0-rc.1, kotlin 1.3.11, AS 3.4 Canary 10, Gradle 5.1
r
Few questions: 1. Can you share the full stacktrace? 2. Do you have the Android Studio plugin installed?
d
@raniejade 1. One of them is
Copy code
1. One of them is 
```java.lang.VerifyError: Bad local variable type
Exception Details:
  Location:
    demo/UtilsKt.isOutOfPreBookingTreshold$default(Ljava/util/Calendar;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Z @67: aload
  Reason:
    Type long_2nd (current frame, locals[4]) is not assignable to reference type
  Current Frame:
    bci: @67
    flags: { }
    locals: { 'java/util/Calendar', 'kotlin/jvm/functions/Function0', integer, long, long_2nd }
    stack: { }
  Bytecode:
    0x0000000: b803 4e3a 041c 047e 9a00 0d19 0411 008a
    0x0000010: 0454 a700 1819 0411 008b 0454 b202 0ac0
    0x0000020: 00f6 4c19 0411 008c 0454 2a12 09b8 000f
    0x0000030: 2b13 018d b800 0f19 0411 008d 0454 2ab6
    0x0000040: 0202 4219 0411 008e 0454 21b8 01ed 65b8
    0x0000050: 01ef 949b 000e 0419 0411 008f 0454 a700
    0x0000060: 0b03 1904 1100 9004 5436 0615 0636 0719
    0x0000070: 0411 0091 0454 1507 9900 0d19 0411 0092
    0x0000080: 0454 a700 112b b901 f201 0057 1904 1100
    0x0000090: 9304 5400 1506 0019 0411 0094 0454 ac  
  Stackmap Table:
    append_frame(@21,Object[#848])
    same_frame(@42)
    full_frame(@97,{Object[#511],Object[#246],Integer,Long},{})
    same_locals_1_stack_item_frame(@105,Integer)
    append_frame(@133,Integer,Integer)
    same_frame(@147)
Copy code
at demo.SdkExtensionsKt.getPriceToDisplay(SdkExtensions.kt:27)
	at demo.SdkExtensionSpek$1$1$1$1.invoke(SdkExtensionSpek.kt:26)
	at demo.SdkExtensionSpek$1$1$1$1.invoke(SdkExtensionSpek.kt:20)
	at org.spekframework.spek2.runtime.scope.TestScopeImpl.execute(Scopes.kt:92)
	at org.spekframework.spek2.runtime.Executor.execute(Executor.kt:28)
	at org.spekframework.spek2.runtime.Executor.execute(Executor.kt:31)
	at org.spekframework.spek2.runtime.Executor.execute(Executor.kt:31)
	at org.spekframework.spek2.runtime.Executor.execute(Executor.kt:31)
	at org.spekframework.spek2.runtime.Executor.execute(Executor.kt:15)
	at org.spekframework.spek2.runtime.AbstractRuntime.execute(SpekRuntime.kt:32)
	at org.spekframework.spek2.junit.SpekTestEngine.execute(SpekTestEngine.kt:55)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:102)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:82)
Copy code
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:78)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
	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:35)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
	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:35)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:175)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:157)
	at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
	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:55)
	at java.lang.Thread.run(Thread.java:748)
2. 2. Unfortunately, no. It does not work us. With the plugin installed we can’t run tests from IDE at all. The stacktrace, for example, is the following
Copy code
null
java.lang.ExceptionInInitializerError
	at demo.Presenter.<init>(MVP.kt:24)
	at demo.splash.SplashPresenter.<init>(SplashPresenter.kt:17)
	at demo.splash.SplashPresenterSpek$1$1$presenter$2.invoke(SplashPresenterSpek.kt:30)
	at demo.splash.SplashPresenterSpek$1$1$presenter$2.invoke(SplashPresenterSpek.kt:25)
	at org.spekframework.spek2.runtime.lifecycle.MemoizedValueAdapter.get(MemoizedValueAdapter.kt:28)
	at org.spekframework.spek2.runtime.lifecycle.MemoizedValueAdapter.getValue(MemoizedValueAdapter.kt:22)
	at demo.splash.SplashPresenterSpek$1$1$1$2.invoke(SplashPresenterSpek.kt:40)
	at demo.splash.SplashPresenterSpek$1$1$1$2.invoke(SplashPresenterSpek.kt:25)
	at org.spekframework.spek2.runtime.scope.TestScopeImpl.execute(Scopes.kt:92)
	at org.spekframework.spek2.runtime.Executor.execute(Executor.kt:28)
	at org.spekframework.spek2.runtime.Executor.execute(Executor.kt:31)
	at org.spekframework.spek2.runtime.Executor.execute(Executor.kt:31)
	at org.spekframework.spek2.runtime.Executor.execute(Executor.kt:31)
	at org.spekframework.spek2.runtime.Executor.execute(Executor.kt:15)
	at org.spekframework.spek2.runtime.AbstractRuntime.execute(SpekRuntime.kt:32)
	at org.spekframework.ide.Spek2ConsoleLauncher.run(console.kt:23)
	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.RuntimeException: Stub!
	at android.content.Intent.<init>(Intent.java:625)
	at demo.UtilsKt.<clinit>(Utils.kt:203)
	... 21 more
r
Let's start with #1. I think spek requires
org.jetbrains.kotlin:kotlin-stdlib-jdk8
and you mentioned you have
org.jetbrains.kotlin:kotlin-stdlib-jdk7
. Does switching to
jdk8
fix your problem?
d
Switching to jdk8 allows only to run tests from AS, and that’s it. To run tests from Gradle jdk7 is enough.
r
By any chance is this an instrumentation test? Also, if you could share a project that can reproduce the issue - it will help me figure out the problem.
d
no. just pure unit test. can’t share for now, sorry. it’s a part of prod stuff. maybe i’ll need to create another demo project, but tomorrow or on monday.
r
Cool, looking forward to the sample 🙂
d
Well, I’ve just dropped everything from the project off except those classes that have failed tests to share it with you, but… tests became green. There’s smth I must investigate more deeply