user1
(Mtb550)
April 2, 2025, 2:14am
1
Hello Dears,
I developed new plugin that has the feature (Run Test).
after trying, I dont know how can I implement it. also I have difficulties to understand the documentation.
the purpose of this feature is run the method once button clicked. same as intellij launcher behavior.
Hi,
Could you please share what you tried to do and where did you got stuck?
user1
(Mtb550)
April 5, 2025, 9:16am
4
Hi @karol.lewandowski
I am trying to run my test method by use ProgramRunnerUtil.
this is my code:
import com.intellij.execution.ProgramRunnerUtil;
import com.intellij.execution.RunManager;
import com.intellij.execution.RunnerAndConfigurationSettings;
import com.intellij.execution.executors.DefaultRunExecutor;
import com.intellij.openapi.project.Project;
import com.theoryinpractice.testng.configuration.TestNGConfiguration;
import com.theoryinpractice.testng.configuration.TestNGConfigurationType;
public class TestNGRunnerByMethod {
public static void runTestMethod(Project project, String fullyQualifiedClassName, String methodName) {
TestNGConfigurationType configType = TestNGConfigurationType.getInstance();
RunManager runManager = RunManager.getInstance(project);
RunnerAndConfigurationSettings settings = runManager.createConfiguration(
"Run " + methodName + " in " + fullyQualifiedClassName,
configType.getConfigurationFactories()[0]);
TestNGConfiguration configuration = (TestNGConfiguration) settings.getConfiguration();
// Set as METHOD test object
configuration.getPersistantData().TEST_OBJECT = TestNGConfiguration.TEST_METHOD;
configuration.getPersistantData().getPackages().clear();
configuration.getPersistantData().getClasses().clear();
configuration.getPersistantData().getMethods().clear();
// Format: className#methodName
configuration.getPersistantData().getMethods().add(fullyQualifiedClassName + "#" + methodName);
runManager.addConfiguration(settings);
runManager.setSelectedConfiguration(settings);
ProgramRunnerUtil.executeConfiguration(settings, DefaultRunExecutor.getRunExecutorInstance());
}
}
Hi,
I don’t see these methods available:
configuration.getPersistantData().getPackages().clear();
configuration.getPersistantData().getClasses().clear();
configuration.getPersistantData().getMethods().clear();
TestData
wasn’t edited for 2 years, so it seems you use quite an old IDE. We recommend supporting the three last major versions, so 2024.1+ at this moment.
Please clarify your project setup (what version do you use) and what happens. Do you get any errors or just nothing happens?