This is an update/repost of <prior post on this ch...
# kotest
s
This is an update/repost of prior post on this channel Does anyone know of an example project in Github (or wherever) that successfully uses Kotest in a multiplatform project with IOS and Android as the targets? I have this type of multiplatform project, and can successfully run/debug unit tests using JUnit5 and the basic kotlin.test stuff. But if I add a Kotest class (in this case extending StringSpec) in the same test source directory and in the same package, the IDE shows it as if it should compile fine. Attempting to run or debug the test using the gutter menu fails. For some reason gradle is not compiling the class before the debug run despite a successful build, so the debug attempt fails with a ClassNotFoundException. The build directory "build\tmp\kotlin-classes\debugUnitTest\com\oldguy\io\tests" is where the compiled class should be, but it is not present. Only the unit test class using kotlin.test is present. It is as if the build doesn't realize the Kotest class is a unit test and skips compiling it. This is using 1.4-M3 and Kotest 4.1.2. The test classes are in the top level androidApp module in the src/test tree of this multiplatform project. I haven't been able so far to get unit tests to run in any of the underlying multiplatform modules due to issue https://youtrack.jetbrains.com/issue/KT-40571. Also, if anyone knows a gradle change to get the build to recognize the Kotest class as a unit test and build it, I would appreciate that info as well. Thanks in advance for any info
l
@AJ Alt is more into mpp stuff. I only used Kotest for Android
s
Are you using the intellij plugin
s
I'm using Android Studio for the Kotest work. But the project I'm working on did start out in Intellij so I could use the new project wizard that came out with 1.4-M3 to generate the multiplatform mobile app project structure. I then imported the project into Android Studio 4.0.1 and am using the Kotest plugin in Android Studio.
s
You can only test stuff in jsTest or jvmTest (or one of the other java based targets).
So you're putting your tests in androidTest and trying to use things from commonMain
that should work as we do the exact same thing in Kotest itself (jvmTest tests things in commonMain)
s
Right, this is in the AndroidApp module of the multiplatform stuff, where all the android/java specific stuff runs fine. The unit tests make use of multiplatform code in the other modules, but kotest is in the android top level module
s
I suspect the problem is with the kotest intellij plugin. There is a new update that changes the way the classpath is generated to be exactly like the junit plugin. So while it wasn't developed with this issue in mind, it could solve it.
s
Hmm, so if i go back to Intellij this might work? Is that new update published?
s
It's not published yet, I might be able to get it out next day or two. I can give it to you in a zip though. Like I say, it's worth a shot since it actually changes the way the classpath works.
s
Wow thanks! If you're looking for a guinea pig, I volunteer :-)
s
You need to install it manually in the plugins page.
s
Ok thanks!! I got stuff going on today but will try it out tomorrow and let you know...
👍🏻 1
s
Even if you tell me it doesn't work that would be helpful
s
Will do.
One more tidbit I just stumbled on before I have to go. I just tried for the first time after adding the kotest class, manually running the androidApp compileDebugUnitTestSources task in gradle, and that does successfully build my unit test class extending StringSpec. But now when I use the gutter icon to run a debug test, the NoClassDefFoundError error changes to a new class: io/github/classgraph/ClassGraph. So there is some combination of a classpath issue, along with the compileDebugUnitTestSources task not happening automatically. Will let you know tomorrow what happens in Idea with the new plugin
👍🏻 1
Installed the new plugin in Android Studio from the zip and restarted. Tried using gutter menu to debug the unit test, but got an error. Looked more carefully at the gradle log and noticed that it ran the androidAppassemble task, instead of assembleAndroidTest. So maybe that's why the unit test wasn't getting compiled. Anyway after androidAppassemble completed successfully, this error happens:
Copy code
Error running 'ByteBufferKoTest': com.intellij.execution.JavaTestFrameworkRunnableState.createHandler(Lcom/intellij/execution/Executor;)Lcom/intellij/execution/process/OSProcessHandler;
I don't see anything useful in idea.log, and am unsure where else to look for diagnostics. BTW, the build.gradle.kts for this app is using JUnitPlatform (junit5) in case that makes a difference.
Hmm, assembleAndroidTest doesn't build the unit tests either, only task compileDebugUnitTestKotlin actually compiles them. Now to figure out which tasks run that (if any) besides compileDebugUnitTestSources
Hmm again, assemble shows compileDebugUnitTestKotlin is in the tasks in the project.afterEvaluate, but doesn't actually run it.
s
intellij should be smart enough to figure out which tasks need to run. That's not part of the plugin framework that I've seen. Does this work if you write a junit5 test?
s
I didn't hit this when I was using junit5 and the kotlin.test stuff, but looking back I was also manually running check and test tasks which do call this thing. So I need to retest using the plugin immediately after a clean.
What about the plugin execution error? is there somewhere I can look to get you more diagnostics? Call stack or whatever?
I agree the assemble not running compileDebugUnitTestKotlin is defintely just a gradle issue and not the plugin. still looking at that.
s
Copy code
Error running 'ByteBufferKoTest': com.intellij.execution.JavaTestFrameworkRunnableState.createHandler(Lcom/intellij/execution/Executor;)Lcom/intellij/execution/process/OSProcessHandler;
My guess here is that the process it's creating is failing. You can see that OSProcessHandler
I don't know where it would log what another process is doing
Are you using the 1.1.0 I uploaded ?
s
Yup, installed from the zip you sent. Think it would act different in Idea instead of Android Studio? I haven't tried that yet
s
I've seen bug reports in other frameworks that seem to indicate android studio does things slightly differently
but for 1.1.0 I basically copy n pasted the junit plugin and just changed the bits that point to kotest
s
Ok lemme try it in Idea. Gotta go, but will be back in under an hour and will try it out. Thanks!
s
I'll make a tweak and give you another version shortly
s
cool...
s
This one should capture the error and show the stack
s
Progress! The new zip won't install in Android Studio. But in Idea it installs fine. And in my test multiplatform project it works now, The gradle issue is still present, so I have to manually run androidAppcompileDebugUnitTestSources task to build the test. Once a built test is present, using the gutter icon to debug the Kotest class works now. So new plugin is good for Idea. In android studio, attempting the install gets an error popup with this text: "Plugin 'kotest' is incompatible with this installation" and nothing changes.
s
ok someone else just posted the same issue
I think I will need to tweak the version strings
s
Cool!
a
Kotest doesn't currently publish an iOS target for any of its libraries, so I wouldn't expect it to work. It would probably be easy to add iOS targets to the assertions libraries, but the JUnit runners are obviously java-only, so I don't think there's a way to use StringSpec etc. for iOS tests.
s
Yeah, currently all my unit tests are only in the androidApp module for that reason.
The plugin version Sam is working on will fix the classpath-related issue I still have in Android Studio, then I'll be good to go. In Idea 1.1.0 fixes the classpath issue and works just fine.
I also can't make kotlin.test unit tests in the commonTest sourceset of any of the multiplatform modules, because of issue KT-40571
s
I'm not sure if the classpath fix will work in studio 😛 I mean it should right, because it works in intellij. But we'll know when I can get the version strings fixed
s
Ruh-Roh. Get my hopes up why don't ya 🙂 Anyway I can guinea pig it whenever you have it. Worth a try - and thanks again for your help.
s
Yeah, I hope it works! It's just a copy n paste of what junit does and that works
s
I did some Idea changes today and now the gutter icon displays the normal popup menu, but clicking either Run or Debug does nothing as far as I can see. No event log error happens, and in idea.log only shows a successful save of the project every time Run or Debug is clicked, no other entries. Today's changes are all because of new updates that evidently popped yesterday or today: • Idea updated/reinstalled to 2020.2 from 2020.1.2 • Kotlin Idea plugin updated to 1.4.0-rc from 1.4-M3 • com.android.tools.build:gradle updated from 3.6.2 to 4.0.0 I'm still using Kotest 4.1.2, and Idea still shows the 1.1.0 Kotest plugin installed and active. But since I upgraded Idea, I did try reinstalling 1.1.0 anyway. After IDE restart it acts the same. Have you tried 1.1.0 in Idea 2020.2 yet?
s
I didn't know 2020.2 was out, is it in EAP?
I also suspect that 1.4.0-rc is breaking things - 4.1.3 is not compiled against 1.4 and it looks like the kotlinx.time stuff has changed (it's experimental, so I suppose they can, although it might be nice to move things out of experimental that are useful, instead of adding pointless features like break in when clauses.)
s
I think it just popped. When I started Idea this morning, the little download message box displayed in bottom right like normal, and I clicked it. It sent me to a web page
s
The latest snapshot on master is compiled against 1.4.0-rc and has all the kotlinx.time stuff removed - if you want to try that
Once 1.4 final drops, I'll release 4.2.0 built against that, with the 1.1.0 plugin final.
s
Ok cool. I'll go find the snapshot and try it out
s
there's a badge on the homepage
s
got it, thanks
Hmm, sonatype repo has all the snaps through 422, but looks like 423 isn't published yet (from the badge). Should I try 422?
Ok I'm wrong, just a sec. the snaps for runner-console-jvm and assertions-core-jvm don't match, lemme change to the latest snaps...
s
console is gone
you don't need that with 1.1.0 plugin or 4.2.0
s
Cool! So assertions-core-jvm at 422 is ok with core 423?
lol I'm trying it, will see
s
yeah should be
looks like 423 failed because sonatype was down
I'll kick off 424 to keep it clean
s
ok great
quick FYI - just for grins I tried building with the 4.2.0.422-SNAPSHOT, and everything builds fine but the plugin still won't run or debug the unit test. I'll wait until I see 424 come out then try that next
s
424 has just completed. We'll see if that makes any difference.
424 is built with 1.4.0-rc. I need to test the plugin myself to see if that's working with kotlin 1.4, and I need to upgrade to 2020.2
s
I just tried it, and the plugin isn't starting anything. It does change the run environment selector in the toolbar to the correct test, but other than that nothing seems to happen. Also, once that environment is selected by the plugin, if I leave it selected and just hit the debug button in the toolbar, still nothing happens. Does that mean whatever is wrong isn't the kotest plugin?
s
It most likely means there's some incompatibility between a) kotlin 1.3 and kotlin 1.4 (especially in the duration stuff) or b) the plugin doesn't like intellij 2020.2 or c) it's because of some of the internal changes coming in 4.2.0 (console dependency has been removed and rolled into the plugin) or all the above.
It's just a matter of working through them until they are fixed. With 1.4.0-rc being binary compatible with 1.4.0 final, I can at least get a 4.2.0 candidate build out.
Sometimes if the plugin crashes they flash an icon in the bottom right which you can use to get a stack trace
Note mine doesn't have the icon atm but it's next to the little man icon when it appears
s
Ok cool. I'm still sniffing around. Funny you mentioned the stack trace, I'm lookig at one right now from the android plugin - i'm trying to verify that I can recreate the same callstack
I don't think this is relevant, but I am getting this error from the android idea plugin. I've gotten it a few times but still don't know what specific action causes it:
Copy code
"Attempted to add more sync issues when the SyncIssueRegistry was sealed!".
I submitted the (lengthy) callstack to Google. Anyway if there are any other tests or diagnostics I can do to help, lemme know. I'll do some more sniffing around tomorrow.
s
Thanks. Does the issue you reference mean the kotest plugin has to be updated for 2020.2? I noticed today the kotlin plugin had an update. I updated the kotlin plugin but still can't start a unit test debug. 2020.2 does successfully do a regular androidApp debug, so basic debug functionality is working.
s
I spent this morning before work updating the plugin to allow separate builds for different intellij versions
I also updated Kotest to remove almost all traces of the kotlinx duration stuff
I haven't had chance to upgrade to 2020.2, install Kotest 426 and test the plugin snapshot yet
But that's my next task
s
No prob, if there's anything lse I can do to help. lemme know 🙂
s
s
Progress! Now clicking debug unit test triggers a build. But after the build completes, this pops in the Event Log: 12:12 PM Error running 'ByteBufferKoTest': Unknown error
and there is a call stack in idea log. just a sec...
2020-07-29 12:12:24,702 [  86217]   INFO - xecution.runners.ExecutionUtil - Error running 'ByteBufferKoTest':<br>Unknown error
java.lang.NullPointerException
at io.kotest.plugin.intellij.run.KotestRunnableState.createHandler(KotestRunnableState.kt:63)
at com.intellij.execution.JavaTestFrameworkRunnableState.execute(JavaTestFrameworkRunnableState.java:189)
at com.intellij.debugger.DefaultDebugEnvironment.createExecutionResult(DefaultDebugEnvironment.java:81)
at com.intellij.debugger.engine.DebugProcessImpl.attachVirtualMachine(DebugProcessImpl.java:2051)
at com.intellij.debugger.impl.DebuggerSession.attach(DebuggerSession.java:434)
at com.intellij.debugger.impl.DebuggerSession.create(DebuggerSession.java:195)
at com.intellij.debugger.impl.DebuggerManagerImpl.attachVirtualMachine(DebuggerManagerImpl.java:182)
at com.intellij.debugger.impl.GenericDebuggerRunner.attachVirtualMachine(GenericDebuggerRunner.java:127)
at com.intellij.debugger.impl.GenericDebuggerRunner.attachVirtualMachine(GenericDebuggerRunner.java:117)
at com.intellij.debugger.impl.GenericDebuggerRunner.createContentDescriptor(GenericDebuggerRunner.java:91)
at com.intellij.execution.JavaTestFrameworkDebuggerRunner.createContentDescriptor(JavaTestFrameworkDebuggerRunner.java:59)
at com.intellij.debugger.impl.GenericDebuggerRunner.doExecute(GenericDebuggerRunner.java:66)
at com.intellij.debugger.impl.GenericDebuggerRunner.lambda$execute$0(GenericDebuggerRunner.java:58)
at com.intellij.execution.ExecutionManager$startRunProfile$1.invoke(ExecutionManager.kt:64)
at com.intellij.execution.ExecutionManager$startRunProfile$1.invoke(ExecutionManager.kt:19)
at com.intellij.execution.impl.ExecutionManagerImpl$startRunProfile$1.invoke(ExecutionManagerImpl.kt:147)
at com.intellij.execution.impl.ExecutionManagerImpl$startRunProfile$1.invoke(ExecutionManagerImpl.kt:60)
at com.intellij.execution.impl.ExecutionManagerImpl$doStartRunProfile$startRunnable$1.run(ExecutionManagerImpl.kt:208)
at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:201)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:802)
at com.intellij.openapi.application.impl.ApplicationImpl.lambda$invokeLater$4(ApplicationImpl.java:322)
at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:84)
at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:132)
at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:47)
at com.intellij.openapi.application.impl.FlushQueue$FlushNow.run(FlushQueue.java:188)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:967)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:839)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:450)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:744)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$9(IdeEventQueue.java:449)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:802)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:497)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
s
awesome thanks
s
NP 🙂
s
This is with the one I uploaded for you an hour ago right ?
s
Yup
Before the new one, the prior one didn't trigger a build. The new one doe the build, then this happens when it's initiating the debug run
s
Yeah I can see the issue
I'm just fixing it
something changed between 2020.1 and .2
s
Cool
s
Success! You da man...
s
so lets confirm what you're using
which version of intellij, kotest
s
Idea 2020.2
Kotlin plugin 1.4.0-rc-release-IJ2020.2-2
s
and the latest kotest snapshot ?
s
Copy code
io.kotest:kotest-core-jvm:4.2.0.424-SNAPSHOT
Anything else?
s
Ok that's cool so it works even with the time stuff in for you
because that was only pulled out in 425 and 426
s
Ok, want me to try 426?
s
Can you try with 426 for me? Just so I know the latest is good. Also you don't have console-jvm in your build anymore right ?
s
lol will do
correct, no more console dependency. just core-jvm and assertions-core-jvm
s
perfect, you will need the junit-jvm in there too if you want to run with gradle
s
Think this plugin version will work in Android Studio as well?
s
the intellij plugin doesn't use junit but the gradle support is built on it
Try it and lets see !
s
Debug success with 426-SNAPSHOT. Going to Android Studio now.
s
I have setup seperate builds for the android studio dependencies but don't have any way of testing it until I install android stuiod
I always seem to have problems getting the android api's downloaded in linux so I usually just give up
s
lol I'm windows so no help there
s
yeah windows or mac will be much easier as there's the nice GUI to do it
I've found it to be a pain
s
Ok in android studio it gets that incompatible version thing and won't install the snapshot plugin. I'm on Android Studio 4.0.1
Here's the message box
s
Ah you need the previous one
Try this
s
Ok will try this, just a sec
s
This is where Android Studio is weird. The latest build (4.0 or 4.1) are actually based on intellij 2019 so are out of date 🤷🏻
so the 2019 one should work on AS 4.1
s
Sounds like google 🙂
s
Earlier versions of AS (if you're using 4.0) might need intellij 2019.2 so I might have to make that as well
s
Ok plugin installed and I'm updating the kotlin plugin. Just a sec for the test
s
🥁
s
Sorry you had to drum for so long 🙂 Debug failed with that same call stack:
java.lang.NullPointerException
at io.kotest.plugin.intellij.run.KotestRunnableState.createHandler(KotestRunnableState.kt:63)
at com.intellij.execution.JavaTestFrameworkRunnableState.execute(JavaTestFrameworkRunnableState.java:160)
at com.intellij.debugger.DefaultDebugEnvironment.createExecutionResult(DefaultDebugEnvironment.java:81)
at com.intellij.debugger.engine.DebugProcessImpl.attachVirtualMachine(DebugProcessImpl.java:1953)
at com.intellij.debugger.impl.DebuggerSession.attach(DebuggerSession.java:434)
at com.intellij.debugger.impl.DebuggerSession.create(DebuggerSession.java:195)
at com.intellij.debugger.impl.DebuggerManagerImpl.attachVirtualMachine(DebuggerManagerImpl.java:185)
at com.intellij.debugger.impl.GenericDebuggerRunner.attachVirtualMachine(GenericDebuggerRunner.java:110)
at com.intellij.debugger.impl.GenericDebuggerRunner.attachVirtualMachine(GenericDebuggerRunner.java:100)
at com.intellij.debugger.impl.GenericDebuggerRunner.createContentDescriptor(GenericDebuggerRunner.java:74)
s
doh
I fixed it in one
s
That's just the top of the stack. lemme know if you need it all
Ok cool
s
no wait I fixed it in both
but forgot to build the other one
s
Still cool :=)
s
Sorry that took so long, had a false start. Anyway it WORKS !!!!
I'm sitting on a breakpoint using 426-SNAPSHOT and that last plugin in Android Studio 4.0.1
I think you would get bored if I types thank you a bunch of times. I sure appreciate the help. Lemme know if there are other specific use cases you want me to try or if there's anything else I can do to help. I'll give the Android Studio environment debugging unit tests a good exercising starting tomorrow :-)
s
That's awesome
Once these are released into the plugin store, the IDE will automatically work out which one is right for your version of the IDE
s
Perfect, I'll keep my eye out...
s
I'll probably hold off until 1.4 is out, so I can release 4.2.0 and 1.1.0 plugin at the same time. With 1.3, the final was only a week after the RC, so maybe same kind of cadence this time.
s
Here's an Android Studio weird tidbit. I had my kotest classes in androidApp/src/test/java and debugging works fine. I moved the identical classes to androidApp/src/test/kotlin and breakpoints stop working. I moved the classes back, and breakpoints work again. I don't understand the inter-dependencies well at all between gradle and the IDE, but my understanding of the "test" sourceSet in androidApp should handle both directories identically. Does this sound like an Android Studio bug to you? I haven't tried to recreate in idea yet.
Or maybe it's the android gradle plugin messing up, I dunno. For now I'm sticking with the java subdir that works :-)
s
It probably means the test folders aren't set right
I've never used android studio
s
It turns out I had to add the src/test/kotlin directory to the android block's "test" sourceSet to make breakpoints work here.
Otherwise so far so good!
👍🏻 1