How to create a XDebugSession or XStackFrame for testing?

Answered

I have created a plugin for visualizing the debugging variables during a debugging session. So far, I have tested the plugin manually.
I want to convert my manual testing to JUnit tests. However, I do not know how/if I can create an XDebugSession or XStackFrame programmatically as if I were debugging through the IDE.
I would like to start a debugging session for a given class file in a given line and then use the associated XStackFrame for my testing.

Maybe someone has an idea how to do this. I do not think the debugger is tested manually when an IntelliJ release happens, so I am nearly certain that this should be possible somehow.

 

Thanks in advance for any help or suggestions!

10 comments
Comment actions Permalink

See com.intellij.debugger.DebuggerTestCase and inheritors in IntelliJ Community sources for plenty of Debugger testing code

1
Comment actions Permalink

Thanks I will have a look!

0
Comment actions Permalink

HI Tim Kräuter,

were you successful in creating the test case by following that class ??

can you pls guide let me to know how you did this?

Thanks in advance for any help or suggestions!

0
Comment actions Permalink

Was a bit busy with other stuff. My current progress can be found here .

Not working yet for some reason but I did not have proper time to look into it. I will post an update once its working for me.

0
Comment actions Permalink

Thank you Tim Kräutern. seen your work, a very cool plugin. 

I am also stuck at this testing part.

Ok, meanwhile I will also check.

looks like this class com.intellij.xdebugger.XBreakpointsTestCase is interesting 

Thanks

 

 

 

 

 

0
Comment actions Permalink

Hi,

I am still struggling to make this work. I tried a similar approach as the class TraceExecutionTestCase.

You can find my current implementation here. The problem is that the test case never finishes because the debug session never pauses.
However, the java file with a comment line indicating a breakpoint gets loaded successfully (see here).

Maybe someone can hint at what I'm doing wrong or a better class to use as a starting point?

Thanks in advance!

1
Comment actions Permalink

Are you getting a 'timeout' problem? I got a similar problem 

I got the timeout problem initially but later timeout problem was solved have some other issues.

https://github.com/bhanuunrivalled/checktest/blob/main/src/test/java/com/github/bhanuunrivalled/checktest/TraceExecutionTestCase.java

There are implementations of DescriptorTestCase in Kotlin language plugin (use IJ Community master sources to obtain), see community/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/KotlinDescriptorTestCase.kt

0
Comment actions Permalink

When I run your code I get the following exception:

Cannot find IntelliJ IDEA project files at C:\Users\Tim\.gradle\caches\modules-2\files-2.1\com.jetbrains.intellij.idea\ideaIC\2021.1.1\e051d885e757b286781f50305504d7b8db3e1dba\ideaIC-2021.1.1
java.io.IOException: Cannot find IntelliJ IDEA project files at C:\Users\Tim\.gradle\caches\modules-2\files-2.1\com.jetbrains.intellij.idea\ideaIC\2021.1.1\e051d885e757b286781f50305504d7b8db3e1dba\ideaIC-2021.1.1
at org.jetbrains.jps.model.serialization.JpsProjectLoader.loadProject(JpsProjectLoader.java:107)
at org.jetbrains.jps.model.serialization.JpsProjectLoader.loadProject(JpsProjectLoader.java:89)
at org.jetbrains.jps.model.serialization.impl.JpsSerializationManagerImpl.loadProject(JpsSerializationManagerImpl.java:32)
at com.intellij.project.IntelliJProjectConfiguration$Companion.loadIntelliJProject(IntelliJProjectConfiguration.kt:91)
at com.intellij.project.IntelliJProjectConfiguration.<init>(IntelliJProjectConfiguration.kt:35)
at com.intellij.project.IntelliJProjectConfiguration$Companion$instance$2.invoke(IntelliJProjectConfiguration.kt:49)
at com.intellij.project.IntelliJProjectConfiguration$Companion$instance$2.invoke(IntelliJProjectConfiguration.kt:48)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at com.intellij.project.IntelliJProjectConfiguration$Companion.getInstance(IntelliJProjectConfiguration.kt)
at com.intellij.project.IntelliJProjectConfiguration$Companion.getProjectLibrary(IntelliJProjectConfiguration.kt:68)
at com.intellij.project.IntelliJProjectConfiguration$Companion.getProjectLibraryClassesRootPaths(IntelliJProjectConfiguration.kt:58)
at com.intellij.project.IntelliJProjectConfiguration.getProjectLibraryClassesRootPaths(IntelliJProjectConfiguration.kt)
at com.intellij.debugger.impl.OutputChecker.lambda$preprocessBuffer$1(OutputChecker.java:205)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:848)
at com.intellij.debugger.impl.OutputChecker.preprocessBuffer(OutputChecker.java:192)
at com.intellij.debugger.impl.OutputChecker.checkValid(OutputChecker.java:128)
at com.intellij.debugger.impl.OutputChecker.checkValid(OutputChecker.java:101)
at com.intellij.debugger.DebuggerTestCase.checkTestOutput(DebuggerTestCase.java:163)
at com.intellij.debugger.DebuggerTestCase.runTestRunnable(DebuggerTestCase.java:137)
at com.intellij.testFramework.HeavyPlatformTestCase.lambda$runBareImpl$23(HeavyPlatformTestCase.java:619)
at com.intellij.execution.ExecutionTestCase.runBareRunnable(ExecutionTestCase.java:131)
at com.intellij.debugger.DebuggerTestCase.runBareRunnable(DebuggerTestCase.java:148)
at com.intellij.testFramework.HeavyPlatformTestCase.runBareImpl(HeavyPlatformTestCase.java:641)
at com.intellij.testFramework.HeavyPlatformTestCase.lambda$runBare$21(HeavyPlatformTestCase.java:585)
at com.intellij.testFramework.UsefulTestCase.lambda$wrapTestRunnable$12(UsefulTestCase.java:537)
at com.intellij.testFramework.HeavyPlatformTestCase.runBare(HeavyPlatformTestCase.java:585)
at com.intellij.testFramework.UsefulTestCase.runBare(UsefulTestCase.java:517)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:252)
at junit.framework.TestSuite.run(TestSuite.java:247)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:121)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.base/java.lang.Thread.run(Thread.java:829)

When I run my test case it neither finishes nor timeouts. Not sure how to proceed at the moment.

0
Comment actions Permalink

Tim Kräuter Unfortunately, these test base classes expect to run inside IntelliJ Project itself, and there's currently no workaround.

0
Comment actions Permalink

Thanks for the information. Then I have to come up with a different way.

0

Please sign in to leave a comment.