Override JUnit Run Provider

I am writing a plugin to run tests for a custom test library.

My RunConfigurationProducer correctly creates a RunConfiguration from the context when the user clicks run on an individual test case.

However, if there is already a JUnit run configuration for this class then the junit configuration always takes preference.

If there is no junit configuration then it works fine.

I am overriding shouldReplace and isPreferredConfiguration (I have tried hardcoding these values to the 4 combinations of true/false).

I have also tried setting order="first" in the plugin xml.

No matter what I try, I cannot get intellij to pick the configuration created by my plugin instead of the junit one.

3 comments
Comment actions Permalink

Please post full sources of your RunConfigurationProducer

 

0
Comment actions Permalink
abstract class TestPathRunConfigurationProducer(private val style: SpecStyle) :
RunConfigurationProducer<KotlinTestRunConfiguration>(KotlinTestConfigurationType::class.java) {

override fun setupConfigurationFromContext(configuration: KotlinTestRunConfiguration,
context: ConfigurationContext,
sourceElement: Ref<PsiElement>): Boolean {
val element = sourceElement.get()
if (element != null) {
val testPath = style.testPath(element)
if (testPath != null) {
configuration.setTestName(testPath)
configuration.setSpec(element.enclosingClass())
configuration.setModule(context.module)
configuration.setGeneratedName()
return true
}
}

return false
}

// compares the existing configurations to the context in question
// if one of the configurations matches then this should return true
override fun isConfigurationFromContext(configuration: KotlinTestRunConfiguration,
context: ConfigurationContext): Boolean {
val element = context.psiLocation
if (element != null) {
val testPath = style.testPath(element)
if (testPath != null) {
val spec = element.enclosingClass()
val name = buildSuggestedName(spec, testPath)
return configuration.name == name
}
}
return false
}
}


Now when the caret is a test (here that is detected by style.testPath(element)) then the run producer is correctly invoked and the correct run config is created.However if you have previously ran a JUnit configuration for this class, then JUnit always "grabs" the config and won't allow this run provider to take precedence. I've tried all combinations of shouldReplace / isPreferred as well as the order field in the plugin.xml

0
Comment actions Permalink

>  However if you have previously ran a JUnit configuration for this class, then JUnit always "grabs" the config and won't allow this run provider to take precedence

 

This behaviour is correct and by intention. And don't say that truly correct but this behaviour is not due to error, but just implemented so.

 

Why it is a problem for you? Already created RC wins.

0

Please sign in to leave a comment.