kotlin-debug-adapter icon indicating copy to clipboard operation
kotlin-debug-adapter copied to clipboard

Unable to attach debugger to a unit test

Open Elpaggio opened this issue 4 years ago • 1 comments

Thanks a lot for a great project! I enjoy the fact that it is now possible to use VSCode to develop and especially debug Kotlin applications.

I know that currently there are no Kotlin test runner and code lens integration in VSCode like with ordinary java projects. However I had hoped that I could use a "poor mans" workaround instead using the Gradle test task wiith the --debug-jvm option in order to attach the kotlin-debug-adapter and break on a breakpoint set in the unit test.

You can clone the demo project from here: https://github.com/Elpaggio/kotlin-demo.git

./gradlew --info cleanTest test --debug-jvm

image

Unfortunately I receive some errors:

[INFO] main Connected to client [INFO] async1 Attaching JVM debug session on localhost:5005 [TRACE] async1 Updating threads [TRACE] async1 Updating breakpoints [DEBUG] eventBus VM Event: VMStartEvent in thread main [DEBUG] eventBus VM Event: ThreadStartEvent in thread main [TRACE] async1 Configured debuggee listeners [DEBUG] eventBus VM Event: ThreadStartEvent in thread /127.0.0.1:50766 to /127.0.0.1:38619 workers [DEBUG] eventBus VM Event: ThreadStartEvent in thread /127.0.0.1:50766 to /127.0.0.1:38619 workers Thread 2 [DEBUG] eventBus VM Event: ThreadStartEvent in thread /127.0.0.1:50766 to /127.0.0.1:38619 workers Thread 3 [DEBUG] eventBus VM Event: ClassPrepareEvent in thread Test worker [TRACE] eventBus Setting breakpoint at prepared type com.example.demo.DemoApplicationTests [DEBUG] eventBus VM Event: ClassPrepareEvent in thread Test worker [TRACE] eventBus Setting breakpoint at prepared type com.example.demo.DemoApplicationTests 2 [DEBUG] eventBus VM Event: [email protected]:9 in thread Test worker [ERROR] server Internal error: java.lang.reflect.InvocationTargetException [ERROR] java.lang.RuntimeException: java.lang.reflect.InvocationTargetException [ERROR] at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:67) [ERROR] at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.request(GenericEndpoint.java:120) [ERROR] at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleRequest(RemoteEndpoint.java:261) [ERROR] at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:190) [ERROR] at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:192) [ERROR] at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94) [ERROR] at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:99) [ERROR] at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [ERROR] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) [ERROR] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [ERROR] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [ERROR] at java.base/java.lang.Thread.run(Thread.java:829) [ERROR] Caused by: java.lang.reflect.InvocationTargetException [ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [ERROR] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

Attaching the kotlin-debug-adapter to the Gradle run task works fine however

./gradlew run --debug-jvm

image

System information: image

Elpaggio avatar Jul 09 '21 08:07 Elpaggio

Hey guys ✌️ Does this mean there is an easy way to just start kotlin-debug-adapter and then use gradle test —debug-jvm for easy debugging tests in a Gradle project?

weilbith avatar Mar 12 '23 19:03 weilbith