JUnit Test Listener
Answered
Hi,
I am creating a plugin and I have a question about creating a JUnit Test Listener. I would like to subscribe some information before start a unit test and unsubscribe after the test and gather some information in the plugin. I looked around and found there is a TestStatusListener, but it is called when the tests are done. Is there a way to use something like com.intellij.rt.execution.junit.IDEAJUnitListener?
My goal is to have something like a console screen of the JUnit output. Thus, when user clicks on a test case, the screen / tool window can show the corresponding information of the test.
Thanks,
Copernicus
Please sign in to leave a comment.
If you want your listener to work in test's VM, you need to register com.intellij.rt.execution.junit.IDEAJUnitListener extension point. Then you would need to ensure that the information you gathered there is passed to the IDEA's VM.
If you want to receive events on IDEA side only, then you probably could use com.intellij.execution.testframework.sm.runner.SMTRunnerEventsListener#TEST_STATUS. You need to subscribe to project message bus like
```
```
Anna
It works really great for me!
Thank you, Anna!
It seems com.intellij.execution.testframework.sm.runner.ui.TestProxyTreeSelectionListener#onSelected is using another way since it is an UI event. I will need to get SMTestRunnerResultsForm and add an EventListener to it?
Yes, it's UI listener and corresponds to the user selection in the tree. It's not available for extension as far as I know.
Oh~ Thank you very much for your help, Anna!