Running JUnit tests from plugin - 'java 1.7' is bad configured exception
Hi,
I'm trying to run JUnit tests from my plugin tests. The code is below. When I run those I get following exception. Any ideas what I'm doing wrong?
java.lang.AssertionError: Error running SimpleTest:<br>'java 1.7' is bad configured
at com.intellij.testFramework.LoggedErrorProcessor$1.processError(LoggedErrorProcessor.java:35)
at com.intellij.testFramework.TestLogger.error(TestLogger.java:53)
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:113)
at com.intellij.execution.runners.ExecutionUtil.handleExecutionError(ExecutionUtil.java:92)
at com.intellij.execution.runners.ExecutionUtil.handleExecutionError(ExecutionUtil.java:52)
at com.intellij.execution.impl.ExecutionManagerImpl$2.run(ExecutionManagerImpl.java:227)
at com.intellij.execution.impl.ExecutionManagerImpl.startRunProfile(ExecutionManagerImpl.java:239)
at com.intellij.execution.impl.ExecutionManagerImpl.startRunProfile(ExecutionManagerImpl.java:255)
at com.intellij.execution.runners.GenericProgramRunner.execute(GenericProgramRunner.java:77)
at com.intellij.execution.runners.GenericProgramRunner.execute(GenericProgramRunner.java:61)
at com.intellij.execution.ProgramRunnerUtil.executeConfiguration(ProgramRunnerUtil.java:138)
at com.intellij.execution.ProgramRunnerUtil.executeConfiguration(ProgramRunnerUtil.java:73)
at com.intellij.execution.ProgramRunnerUtil.executeConfiguration(ProgramRunnerUtil.java:153)
at com.test.SimpleTest.testSimple(SimpleTest.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at com.intellij.testFramework.UsefulTestCase.access$001(UsefulTestCase.java:75)
at com.intellij.testFramework.UsefulTestCase$2.run(UsefulTestCase.java:306)
Test code:
public class SimpleTestInPlugin extends LightCodeInsightFixtureTestCase {
@Override
protected String getTestDataPath() {
return "testData";
}
//
// @NotNull
// @Override
// protected LightProjectDescriptor getProjectDescriptor() {
// return JAVA_1_7;
// }
public void testSimple() {
PsiFile testFile = myFixture.configureByFile("SimpleTest.java");
PsiClass testClass = null;
if(testFile instanceof PsiJavaFile) {
PsiJavaFile javaFile = (PsiJavaFile) testFile;
testClass = javaFile.getClasses()[0];
}
RunManager runManager = RunManager.getInstance(getProject());
RunnerAndConfigurationSettings runnerAndConfigurationSettings = runManager.createRunConfiguration(
"sampleConfig", JUnitConfigurationType.getInstance().getConfigurationFactories()[0]);
JUnitConfiguration tdaConfiguration = (JUnitConfiguration) runnerAndConfigurationSettings.getConfiguration();
tdaConfiguration.getPersistentData().TEST_OBJECT = JUnitConfiguration.TEST_CLASS;
tdaConfiguration.getPersistentData().setMainClass(testClass);
tdaConfiguration.getPersistentData().setScope(TestSearchScope.WHOLE_PROJECT);
tdaConfiguration.beClassConfiguration(testClass);
tdaConfiguration.setModule(myModule);
tdaConfiguration.setVMParameters("-ea");
//tdaConfiguration.setWorkingDirectory("X:\\");
Executor executor = DefaultRunExecutor.getRunExecutorInstance();
ProgramRunnerUtil.executeConfiguration(getProject(), runnerAndConfigurationSettings, executor);
}
}
SimpleTest.java (test executed by plugin test):
public class SimpleTest {
@org.junit.Test
public void testA() throws Exception {
}
}
Please sign in to leave a comment.
Hi globtroter,
it is a bit confusing that your Test code class and the class that should get Tested have the same name.
And I don't know what you would like to achieve with:
PsiFile testFile = myFixture.configureByFile("SimpleTest.java");Maybe you could explain a little more details.
Markus
Hi Markus,
I've just renamed tests to be more self-explanatory. My plugin monitors test execution and acts on it. To test the plugin I wrote the SimpleTestInPlugin test. It copies SimpleTest.java (from testData) into virtual project (is it ok to copy it to src/ instead of tst/?) and runs it (testA() method). Does that answer your question?
actually I don't know the answer.
But I see some weird code:
This line of code overwrites these two lines:
Another thing you could try is to set the name of the Testclass to SimpleTest istead of SimpleTest.java:
PsiFile testFile = myFixture.configureByFile("SimpleTest.java");You could also deactivate the Assertions with:
//tdaConfiguration.setVMParameters("-ea");But this could be not smart if you want to test something.
I can't see where you do the copy action of the SimpleTest class
Markus
I've tried all of these to no avail (same exception occurs). Any other ideas?
@Markus: could you possibly share a full piece of code that you're using to run the tests from the other thread?
This is the whole class which executes the tests I selected in a Dialog. It is implemented as an Listener for a Button in the Dialog itself. I hope this helps you.