use of com.intellij.execution.junit.JUnitConfiguration in project intellij-community by JetBrains.
the class JUnit4IntegrationTest method ignoredTestMethod.
@Test
public void ignoredTestMethod() throws Throwable {
EdtTestUtil.runInEdtAndWait(() -> {
PsiClass psiClass = findClass(getModule1(), CLASS_NAME);
assertNotNull(psiClass);
PsiMethod testMethod = psiClass.findMethodsByName(METHOD_NAME, false)[0];
JUnitConfiguration configuration = createConfiguration(testMethod);
Executor executor = DefaultRunExecutor.getRunExecutorInstance();
RunnerAndConfigurationSettingsImpl settings = new RunnerAndConfigurationSettingsImpl(RunManagerImpl.getInstanceImpl(getProject()), configuration, false);
ExecutionEnvironment environment = new ExecutionEnvironment(executor, ProgramRunnerUtil.getRunner(DefaultRunExecutor.EXECUTOR_ID, settings), settings, getProject());
TestObject state = configuration.getState(executor, environment);
JavaParameters parameters = state.getJavaParameters();
parameters.setUseDynamicClasspath(getProject());
GeneralCommandLine commandLine = parameters.toCommandLine();
StringBuffer buf = new StringBuffer();
StringBuffer err = new StringBuffer();
OSProcessHandler process = new OSProcessHandler(commandLine);
process.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
String text = event.getText();
try {
if (outputType == ProcessOutputTypes.STDOUT && !text.isEmpty() && ServiceMessage.parse(text.trim()) == null) {
buf.append(text);
}
if (outputType == ProcessOutputTypes.STDERR) {
err.append(text);
}
} catch (ParseException e) {
e.printStackTrace();
}
}
});
process.startNotify();
process.waitFor();
process.destroyProcess();
String testOutput = buf.toString();
assertEmpty(err.toString());
switch(myJUnitVersion) {
//shouldn't work for old versions
case "4.4":
//shouldn't work for old versions
case "4.5":
break;
default:
assertTrue(testOutput, testOutput.contains("Test1"));
}
});
}
use of com.intellij.execution.junit.JUnitConfiguration in project intellij-community by JetBrains.
the class ConfigurationRefactoringsTest method testRenameJUnitPackage.
public void testRenameJUnitPackage() throws IOException {
PsiPackage psiPackage = mySource.createPackage("pkg");
JUnitConfiguration configuration = createJUnitConfiguration(psiPackage, AllInPackageConfigurationProducer.class, new MapDataContext());
rename(psiPackage, "pkg2");
checkPackage("pkg2", configuration);
PsiPackage outer = mySource.createPackage("outerPkg");
move(JavaPsiFacade.getInstance(myProject).findPackage("pkg2"), outer.getQualifiedName());
checkPackage("outerPkg.pkg2", configuration);
rename(outer, "outer2");
checkPackage("outer2.pkg2", configuration);
}
use of com.intellij.execution.junit.JUnitConfiguration in project intellij-community by JetBrains.
the class ConfigurationRefactoringsTest method testRenameBadTestClass.
public void testRenameBadTestClass() throws IOException {
PsiClass psiClass = mySource.createClass("NotATest", NOT_A_TEST);
assertNotNull(psiClass);
JUnitConfigurationType instance = JUnitConfigurationType.getInstance();
assertNotNull(instance);
JUnitConfiguration configuration = new JUnitConfiguration("notATest", myProject, instance.getConfigurationFactories()[0]);
configuration.setMainClass(psiClass);
configuration.setModule(configuration.getValidModules().iterator().next());
checkConfigurationException("NotATest isn't test class", configuration);
RunManagerEx.getInstanceEx(myProject).setTemporaryConfiguration(new RunnerAndConfigurationSettingsImpl(null, configuration, false));
rename(psiClass, "NotATest2");
JUnitConfiguration.Data data = configuration.getPersistentData();
assertEquals("NotATest2", data.getMainClassName());
data.METHOD_NAME = "test";
data.TEST_OBJECT = JUnitConfiguration.TEST_METHOD;
checkConfigurationException("Test method 'test' doesn't exist", configuration);
rename(psiClass.findMethodsByName("test", false)[0], "test2");
assertEquals("NotATest2", data.getMainClassName());
assertEquals("test2", data.getMethodName());
}
use of com.intellij.execution.junit.JUnitConfiguration in project intellij-community by JetBrains.
the class ConfigurationRefactoringsTest method testRefactorOtherClass.
public void testRefactorOtherClass() throws IOException {
PsiClass psiClass = mySource.createClass("ATest", TEST_CODE);
assertNotNull(psiClass);
JUnitConfiguration configuration = createConfiguration(psiClass);
psiClass = mySource.createClass("Application", APPLICATION_CODE);
assertNotNull(psiClass);
rename(psiClass, "NewName");
checkClassName("ATest", configuration);
mySource.createPackage("pkg");
psiClass = mySource.findClass("NewName");
assertNotNull(psiClass);
move(psiClass, "pkg");
checkClassName("ATest", configuration);
}
use of com.intellij.execution.junit.JUnitConfiguration in project intellij-community by JetBrains.
the class ConfigurationRefactoringsTest method testRefactorTestMethod.
public void testRefactorTestMethod() throws IOException {
PsiClass psiClass = mySource.createClass("ATest", TEST_CODE);
assertNotNull(psiClass);
PsiMethod testMethod = psiClass.findMethodsByName("test", false)[0];
JUnitConfiguration configuration = createConfiguration(testMethod);
rename(testMethod, "test1");
checkMethodName("test1", configuration);
checkClassName("ATest", configuration);
assertEquals("ATest.test1", configuration.getName());
move(psiClass, "pkg");
checkClassName("pkg.ATest", configuration);
psiClass = configuration.getConfigurationModule().findClass(configuration.getPersistentData().getMainClassName());
rename(psiClass, "TestClassName");
assertEquals("TestClassName.test1", configuration.getName());
psiClass = configuration.getConfigurationModule().findClass(configuration.getPersistentData().getMainClassName());
PsiClass otherTest = mySource.createClass("ATest", TEST_CODE);
HashSet<PsiMember> members = new HashSet<>();
assertNotNull(psiClass);
members.add(psiClass.findMethodsByName("test1", false)[0]);
moveMembers(otherTest, members);
psiClass = configuration.getConfigurationModule().findClass(configuration.getPersistentData().getMainClassName());
checkMethodName("test1", configuration);
checkClassName("ATest", configuration);
assertEquals("ATest.test1", configuration.getName());
assertNotNull(psiClass);
PsiMethod otherMethod = psiClass.findMethodsByName("otherMethod", false)[0];
rename(otherMethod, "newName");
checkMethodName("test1", configuration);
}
Aggregations