Search in sources :

Example 51 with Location

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PsiElement(com.intellij.psi.PsiElement) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) Location(com.intellij.execution.Location) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation)

Example 52 with Location

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);
        }
    }
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) PsiElement(com.intellij.psi.PsiElement) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) Location(com.intellij.execution.Location)

Example 53 with Location

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());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) JUnitConsoleProperties(com.intellij.execution.junit2.ui.properties.JUnitConsoleProperties) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location) Navigatable(com.intellij.pom.Navigatable)

Example 54 with Location

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));
}
Also used : Project(com.intellij.openapi.project.Project) SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) JavaTestLocator(com.intellij.execution.testframework.JavaTestLocator) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location)

Example 55 with Location

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);
}
Also used : SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location)

Aggregations

Location (com.intellij.execution.Location)64 PsiElement (com.intellij.psi.PsiElement)21 PsiClass (com.intellij.psi.PsiClass)19 VirtualFile (com.intellij.openapi.vfs.VirtualFile)18 PsiMemberParameterizedLocation (com.intellij.execution.junit2.PsiMemberParameterizedLocation)17 PsiLocation (com.intellij.execution.PsiLocation)16 MethodLocation (com.intellij.execution.junit2.info.MethodLocation)16 Project (com.intellij.openapi.project.Project)15 Module (com.intellij.openapi.module.Module)13 PsiMethod (com.intellij.psi.PsiMethod)11 PsiFile (com.intellij.psi.PsiFile)8 Nullable (org.jetbrains.annotations.Nullable)8 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)7 SMTestProxy (com.intellij.execution.testframework.sm.runner.SMTestProxy)6 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)6 PatternConfigurationProducer (com.intellij.execution.junit.PatternConfigurationProducer)5 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)3 AbstractTestProxy (com.intellij.execution.testframework.AbstractTestProxy)3 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)3