How to run test of the project from plugin? Follow
Hello.
My question is simple: I need any solution, how to run some test from the current project, using Open API (for example).
So, input data of this issue is: a set of PsiFiles, which are test java classes.
Output (need) is: the result of test-running in any view.
Thank you.
Please sign in to leave a comment.
Ok, I see, that my question is very stupid or it is some secret information. I will restate this question, so I believe, that valiant programmers from JetBrains will graciously answer for my trouble.
Simply, I need a way to run using JUnit-plugin some set of PsiClasses, which are known to be test-case classes.
Thank you!
There is only silence.
Ok. I'm trying to solve my problem. I found, that in JUnit and TestNG sources use this common code:
final Executor executor = isDebug ? DefaultDebugExecutor.getDebugExecutorInstance() : DefaultRunExecutor.getRunExecutorInstance();
final ProgramRunner runner = RunnerRegistry.getInstance().getRunner(executor.getId(), profile);
But classes ProgramRunner and RunnerRegistry,Executor, DefaultDebugExecutor and DefaultRunExecutor are unknown! For example, ProgramRunner must be in com.intellij.execution.runners - but it isn't!
Hello Andremoniy,
These classes have been added in IDEA 8. You should look at IDEA 7 version
of the JUnit and TestNG plugins.
However, you shouldn't need to use these APIs at all. It's much easier to
create a standard JUnit configuration for your class and to run it using
the usual API.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Hi, Dmitry!
You wrote:
However, there isn't any suitable documentation about this API-aspect: how to compile and run some class.
But, on the last week I found such solution:
+ JUnitConfigurationType configurationType = JUnitConfigurationType.getInstance();+
+ ConfigurationFactory configurationFactory = configurationType.getConfigurationFactories()[0];+
+ JUnitConfiguration configuration = new JUnitConfiguration("TA Tests", project, configurationFactory);+
+ RunStrategyImpl runStrategy = new RunStrategyImpl();+
+ DataContext dataContext = SimpleDataContext.getProjectContext(project);+
+ JavaProgramRunner javaRunner = ExecutionRegistryImpl.getInstance().getDefaultRunner();+
+ PsiClass testClass = RunTestingAction.getClassElementFromPsiJavaFile(testFile);+
+ configuration.beClassConfiguration(testClass); +
+ configuration.setMainClass(testClass);+
+ ConfigurationPerRunnerSettings confPerRunSettings = new ConfigurationPerRunnerSettings(javaRunner.getInfo(), configuration);+
+ RunnerSettings runSettings = new RunnerSettings(configuration, configuration);+
+ try {+
+ runStrategy.execute(configuration, dataContext, javaRunner, runSettings, confPerRunSettings);+
+ } catch (ExecutionException e1) {+
+ // ingore+
+ }+
It runs full build of project and than runs my testClass.
This has minus, because I don't need to rebuild my project, but only recompile.
Hi Dmitry
could you please provide an example of how this can be done?
Markus