use of com.intellij.execution.testframework.JavaTestLocator 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");
}
use of com.intellij.execution.testframework.JavaTestLocator 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.testframework.JavaTestLocator in project intellij-community by JetBrains.
the class DetectClassesToRunTest method testRerunFailedParameterized.
public void testRerunFailedParameterized() throws Exception {
@SuppressWarnings("TestNGDataProvider") final PsiClass aClass = myFixture.addClass("package a; " + "import org.testng.annotations.DataProvider;\n" + "import org.testng.annotations.Test;\n" + "\n" + "import static org.testng.Assert.assertEquals;\n" + "\n" + "public class ATest {\n" + "\n" + " @DataProvider\n" + " public Object[][] testData() {\n" + " return new Object[][]{\n" + " {1},\n" + " {2},\n" + " };\n" + " }\n" + "\n" + " @Test(dataProvider = \"testData\")\n" + " public void test(int in) {\n" + " assertEquals(in, 0);\n" + " }\n" + "}\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("test", false, "java:test://a.ATest.test[0]");
testProxy.setLocator(new JavaTestLocator());
RerunFailedTestsAction.includeFailedTestWithDependencies(classes, projectScope, getProject(), testProxy);
final SMTestProxy testProxy2 = new SMTestProxy("test", false, "java:test://a.ATest.test[1]");
testProxy2.setLocator(new JavaTestLocator());
RerunFailedTestsAction.includeFailedTestWithDependencies(classes, projectScope, getProject(), testProxy2);
assertEquals(1, classes.size());
final Map<PsiMethod, List<String>> params = classes.get(aClass);
final PsiMethod[] tests = aClass.findMethodsByName("test", false);
assertContainsElements(params.keySet(), tests);
final List<String> paramsToRerun = params.get(tests[0]);
assertEquals(2, paramsToRerun.size());
assertContainsElements(paramsToRerun, "0", "1");
}
Aggregations