use of com.intellij.psi.PsiMethod 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.psi.PsiMethod in project intellij-community by JetBrains.
the class JUnit5AcceptanceTest method testFactoryMethods.
@Test
void testFactoryMethods() {
doTest(() -> {
PsiClass aClass = myFixture.addClass("class MyTest {@org.junit.jupiter.api.TestFactory java.util.List<org.junit.jupiter.api.DynamicTest> tests() {return null;}}");
PsiMethod factoryMethod = aClass.getMethods()[0];
assertNotNull(factoryMethod);
assertTrue(JUnitUtil.isTestAnnotated(factoryMethod));
});
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class JUnitRerunFailedTestsTest method testIncludeMethodsToRerunFromChildClass.
public void testIncludeMethodsToRerunFromChildClass() throws Exception {
myFixture.addClass("abstract class ATest extends junit.framework.TestCase {" + " public void testMe() {}\n" + "}");
myFixture.addClass("public class ChildTest extends ATest {}");
final SMTestProxy testProxy = new SMTestProxy("testMe", false, "java:test://ChildTest.testMe");
final Project project = getProject();
final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
testProxy.setLocator(JavaTestLocator.INSTANCE);
final Location location = testProxy.getLocation(project, searchScope);
assertNotNull(location);
assertInstanceOf(location, MethodLocation.class);
//navigation to the method in abstract super class
final PsiElement element = location.getPsiElement();
assertInstanceOf(element, PsiMethod.class);
final PsiMethod method = (PsiMethod) element;
assertEquals("testMe", method.getName());
final PsiClass containingClass = method.getContainingClass();
assertNotNull(containingClass);
assertEquals("ATest", containingClass.getQualifiedName());
//include method "from" child class to rerun
final String presentation = TestMethods.getTestPresentation(testProxy, project, searchScope);
assertEquals("ChildTest,testMe", presentation);
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class JUnitRerunFailedTestsTest method testInnerClass.
public void testInnerClass() throws Exception {
myFixture.addClass("public class TestClass {\n" + " public static class Tests extends junit.framework.TestCase {\n" + " public void testFoo() throws Exception {}\n" + " }\n" + "}");
final SMTestProxy testProxy = new SMTestProxy("testFoo", false, "java:test://TestClass$Tests.testFoo");
final Project project = getProject();
final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
testProxy.setLocator(JavaTestLocator.INSTANCE);
Location location = testProxy.getLocation(project, searchScope);
assertNotNull(location);
PsiElement element = location.getPsiElement();
assertTrue(element instanceof PsiMethod);
String name = ((PsiMethod) element).getName();
assertEquals("testFoo", name);
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class TestMethods method getTestPresentation.
@Nullable
public static String getTestPresentation(AbstractTestProxy testInfo, Project project, GlobalSearchScope searchScope) {
final Location location = testInfo.getLocation(project, searchScope);
final PsiElement element = location != null ? location.getPsiElement() : null;
if (element instanceof PsiMethod) {
final PsiClass containingClass = location instanceof MethodLocation ? ((MethodLocation) location).getContainingClass() : location instanceof PsiMemberParameterizedLocation ? ((PsiMemberParameterizedLocation) location).getContainingClass() : ((PsiMethod) element).getContainingClass();
if (containingClass != null) {
final String proxyName = testInfo.getName();
final String methodName = ((PsiMethod) element).getName();
return JavaExecutionUtil.getRuntimeQualifiedName(containingClass) + "," + (proxyName.contains(methodName) ? proxyName.substring(proxyName.indexOf(methodName)) : methodName);
}
}
return null;
}
Aggregations