use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class PatternConfigurationProducer method setupConfigurationFromContext.
@Override
protected boolean setupConfigurationFromContext(JUnitConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
final LinkedHashSet<String> classes = new LinkedHashSet<>();
final PsiElement element = checkPatterns(context, classes);
if (element == null) {
return false;
}
sourceElement.set(element);
final JUnitConfiguration.Data data = configuration.getPersistentData();
data.setPatterns(classes);
data.TEST_OBJECT = JUnitConfiguration.TEST_PATTERN;
data.setScope(setupPackageConfiguration(context, configuration, data.getScope()));
configuration.setGeneratedName();
final Location contextLocation = context.getLocation();
if (contextLocation instanceof PsiMemberParameterizedLocation) {
final String paramSetName = ((PsiMemberParameterizedLocation) contextLocation).getParamSetName();
if (paramSetName != null) {
configuration.setProgramParameters(paramSetName);
}
}
return true;
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class RerunFailedTestsAction method includeFailedTestWithDependencies.
public static void includeFailedTestWithDependencies(Map<PsiClass, Map<PsiMethod, List<String>>> classes, GlobalSearchScope scope, Project project, AbstractTestProxy proxy) {
final Location location = proxy.getLocation(project, scope);
if (location != null) {
final PsiElement element = location.getPsiElement();
if (element instanceof PsiMethod && element.isValid()) {
final PsiMethod psiMethod = (PsiMethod) element;
PsiClass psiClass = psiMethod.getContainingClass();
if (psiClass != null && psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
final AbstractTestProxy parent = proxy.getParent();
final PsiElement elt = parent != null ? parent.getLocation(project, scope).getPsiElement() : null;
if (elt instanceof PsiClass) {
psiClass = (PsiClass) elt;
}
}
TestNGTestObject.collectTestMethods(classes, psiClass, psiMethod.getName(), scope);
Map<PsiMethod, List<String>> psiMethods = classes.get(psiClass);
if (psiMethods == null) {
psiMethods = new LinkedHashMap<>();
classes.put(psiClass, psiMethods);
}
List<String> strings = psiMethods.get(psiMethod);
if (strings == null || strings.isEmpty()) {
strings = new ArrayList<>();
}
setupParameterName(location, strings);
psiMethods.put(psiMethod, strings);
}
}
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class JUnitOpenSourceAtExceptionTest method testStackTraceParseerAcceptsJavaStacktrace.
public void testStackTraceParseerAcceptsJavaStacktrace() throws Exception {
myFixture.addClass("abstract class ATest extends junit.framework.TestCase {" + " public void testMe() {\n" + " int i = 0;\n" + " int j = 0;\n" + " int k = 0;\n" + " fail();\n" + " }\n" + "}");
myFixture.addClass("public class ChildTest extends ATest {}");
final SMTestProxy testProxy = new SMTestProxy("testMe", false, "java:test://ChildTest.testMe");
testProxy.setTestFailed("failure", "\tat junit.framework.Assert.fail(Assert.java:57)\n" + "\tat junit.framework.Assert.failNotEquals(Assert.java:329)\n" + "\tat junit.framework.Assert.assertEquals(Assert.java:78)\n" + "\tat junit.framework.Assert.assertEquals(Assert.java:234)\n" + "\tat junit.framework.Assert.assertEquals(Assert.java:241)\n" + "\tat junit.framework.TestCase.assertEquals(TestCase.java:409)\n" + "\tat ATest.testMe(Dummy.java:6)\n", true);
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);
final JUnitConfiguration configuration = new JUnitConfiguration("p", getProject(), JUnitConfigurationType.getInstance().getConfigurationFactories()[0]);
final Navigatable descriptor = testProxy.getDescriptor(location, new JUnitConsoleProperties(configuration, DefaultRunExecutor.getRunExecutorInstance()));
assertInstanceOf(descriptor, OpenFileDescriptor.class);
final OpenFileDescriptor fileDescriptor = (OpenFileDescriptor) descriptor;
final VirtualFile file = fileDescriptor.getFile();
assertNotNull(file);
assertEquals(5, fileDescriptor.getLine());
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class JUnitRerunFailedTestsTest method testParameterizedTestNavigation.
public void testParameterizedTestNavigation() throws Exception {
myFixture.addClass("package org.junit.runner;\n" + "public @interface RunWith {\n" + " Class<? extends Runner> value();\n" + "}");
myFixture.addClass("package org.junit.runners; public class Parameterized {}");
final PsiClass testClass = myFixture.addClass("import org.junit.Test;\n" + "import org.junit.runner.RunWith;\n" + "import org.junit.runners.Parameterized;\n" + "@RunWith(Parameterized.class)\n" + "public class MyTest {\n" + " @Test\n" + " public void testName1() throws Exception {}\n" + "}");
final Project project = getProject();
final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
final JavaTestLocator locationProvider = JavaTestLocator.INSTANCE;
final SMTestProxy rootProxy = new SMTestProxy("MyTest", true, "java:suite://MyTest");
rootProxy.setLocator(locationProvider);
final SMTestProxy proxyParam = new SMTestProxy("[0.java]", true, "java:suite://MyTest.[0.java]");
proxyParam.setLocator(locationProvider);
final SMTestProxy parameterizedTestProxy = new SMTestProxy("testName1[0.java]", false, "java:test://MyTest.testName1[0.java]");
parameterizedTestProxy.setLocator(locationProvider);
final Location rootLocation = rootProxy.getLocation(project, searchScope);
assertNotNull(rootLocation);
assertEquals(testClass, rootLocation.getPsiElement());
final Location proxyParamLocation = proxyParam.getLocation(project, searchScope);
assertNotNull(proxyParamLocation);
assertInstanceOf(proxyParamLocation, PsiMemberParameterizedLocation.class);
assertEquals("[0.java]", ((PsiMemberParameterizedLocation) proxyParamLocation).getParamSetName());
assertEquals(testClass, proxyParamLocation.getPsiElement());
final Location parameterizedTestProxyLocation = parameterizedTestProxy.getLocation(project, searchScope);
assertNotNull(parameterizedTestProxyLocation);
assertInstanceOf(parameterizedTestProxyLocation, PsiMemberParameterizedLocation.class);
assertEquals("[0.java]", ((PsiMemberParameterizedLocation) parameterizedTestProxyLocation).getParamSetName());
assertEquals(testClass.getMethods()[0], parameterizedTestProxyLocation.getPsiElement());
assertEquals(testClass, ((PsiMemberParameterizedLocation) parameterizedTestProxyLocation).getContainingClass());
assertEquals("MyTest,testName1[0.java]", TestMethods.getTestPresentation(parameterizedTestProxy, project, searchScope));
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class JUnitRerunFailedTestsTest method testLocatorForIgnoredClass.
public void testLocatorForIgnoredClass() throws Exception {
PsiClass aClass = myFixture.addClass("@org.junit.Ignore" + "public class TestClass {\n" + " @org.junit.Test" + " public void testFoo() throws Exception {}\n" + "}");
final SMTestProxy testProxy = new SMTestProxy("TestClass", false, "java:test://TestClass.TestClass");
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();
assertEquals(aClass, element);
}
Aggregations