Search in sources :

Example 1 with SMTestProxy

use of com.intellij.execution.testframework.sm.runner.SMTestProxy in project intellij-community by JetBrains.

the class DetectClassesToRunTest method testRerunFailedTestWithDependency.

public void testRerunFailedTestWithDependency() throws Exception {
    final PsiClass aClass = myFixture.addClass("package a; public class ATest {" + "  @org.testng.annotations.Test()\n" + "  public void testTwo(){}\n " + "  @org.testng.annotations.Test(dependsOnMethods = \"testTwo\")\n" + //parameterized
    "  public void testOne(String s){}\n" + "}");
    final LinkedHashMap<PsiClass, Map<PsiMethod, List<String>>> classes = new LinkedHashMap<>();
    classes.put(aClass, new HashMap<>());
    final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(getProject());
    final SMTestProxy testProxy = new SMTestProxy("testOne", false, "java:test://a.ATest.testOne[a]");
    testProxy.setLocator(new JavaTestLocator());
    RerunFailedTestsAction.includeFailedTestWithDependencies(classes, projectScope, getProject(), testProxy);
    assertEquals(1, classes.size());
    final Map<PsiMethod, List<String>> params = classes.get(aClass);
    assertContainsElements(params.keySet(), aClass.getMethods());
    final List<String> paramsToRerun = params.get(aClass.findMethodsByName("testOne", false)[0]);
    assertEquals(1, paramsToRerun.size());
    assertContainsElements(paramsToRerun, "a");
}
Also used : SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) LinkedHashMap(java.util.LinkedHashMap) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) List(java.util.List) JavaTestLocator(com.intellij.execution.testframework.JavaTestLocator) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with SMTestProxy

use of com.intellij.execution.testframework.sm.runner.SMTestProxy in project intellij-community by JetBrains.

the class JUnitRerunFailedTestsTest method testIgnoreRenamedMethodInRerunFailed.

public void testIgnoreRenamedMethodInRerunFailed() throws Exception {
    final PsiClass baseClass = 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 String presentation = TestMethods.getTestPresentation(testProxy, project, searchScope);
    assertEquals("ChildTest,testMe", presentation);
    WriteCommandAction.runWriteCommandAction(project, () -> {
        baseClass.getMethods()[0].setName("testName2");
    });
    assertNull(TestMethods.getTestPresentation(testProxy, project, searchScope));
}
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)

Example 3 with SMTestProxy

use of com.intellij.execution.testframework.sm.runner.SMTestProxy 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);
}
Also used : SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiMethod(com.intellij.psi.PsiMethod) 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)

Example 4 with SMTestProxy

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

Example 5 with SMTestProxy

use of com.intellij.execution.testframework.sm.runner.SMTestProxy in project intellij-community by JetBrains.

the class PyAbstractTestProcessRunner method assertAllTestsAreResolved.

/**
   * Ensures all test locations are resolved (i.e. user may click on test and navigate to it)
   * All tests are checked but [root] (it never resolves).
   */
public final void assertAllTestsAreResolved(@NotNull final Project project) {
    final List<SMTestProxy> allTests = getTestProxy().getAllTests();
    assert !allTests.isEmpty() : "No tests at all.";
    final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
    EdtTestUtil.runInEdtAndWait(() -> allTests.subList(1, allTests.size()).forEach(t -> Assert.assertNotNull("No location " + t, t.getLocation(project, scope))));
}
Also used : ExecutionException(com.intellij.execution.ExecutionException) EdtTestUtil(com.intellij.testFramework.EdtTestUtil) ModalityState(com.intellij.openapi.application.ModalityState) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) AbstractPythonRunConfigurationParams(com.jetbrains.python.run.AbstractPythonRunConfigurationParams) Filter(com.intellij.execution.testframework.Filter) RerunFailedActionsTestTools(com.intellij.execution.testframework.actions.RerunFailedActionsTestTools) Project(com.intellij.openapi.project.Project) SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) Logger(com.intellij.openapi.diagnostic.Logger) SMRootTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy.SMRootTestProxy) ProgramRunner(com.intellij.execution.runners.ProgramRunner) ConsoleViewImpl(com.intellij.execution.impl.ConsoleViewImpl) StringUtil(com.intellij.openapi.util.text.StringUtil) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) ProcessHandler(com.intellij.execution.process.ProcessHandler) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SMTRunnerConsoleView(com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) Assert(org.junit.Assert) Ref(com.intellij.openapi.util.Ref) javax.swing(javax.swing) SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Aggregations

SMTestProxy (com.intellij.execution.testframework.sm.runner.SMTestProxy)42 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)9 Project (com.intellij.openapi.project.Project)8 Location (com.intellij.execution.Location)6 PsiClass (com.intellij.psi.PsiClass)6 MethodLocation (com.intellij.execution.junit2.info.MethodLocation)5 PsiMemberParameterizedLocation (com.intellij.execution.junit2.PsiMemberParameterizedLocation)4 PsiElement (com.intellij.psi.PsiElement)4 PsiMethod (com.intellij.psi.PsiMethod)4 JavaTestLocator (com.intellij.execution.testframework.JavaTestLocator)3 List (java.util.List)3 AbstractTestProxy (com.intellij.execution.testframework.AbstractTestProxy)2 SMTRunnerTreeStructure (com.intellij.execution.testframework.sm.runner.SMTRunnerTreeStructure)2 Ref (com.intellij.openapi.util.Ref)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 NotNull (org.jetbrains.annotations.NotNull)2 ExecutionException (com.intellij.execution.ExecutionException)1 JavaTestConfigurationBase (com.intellij.execution.JavaTestConfigurationBase)1