junit: test to ensure that test from concrete class would be rerun

This commit is contained in:
Anna Kozlova
2015-04-10 20:03:53 +02:00
parent 95b81e4340
commit c53d2b910d
3 changed files with 85 additions and 15 deletions
+3 -2
View File
@@ -4,6 +4,7 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
@@ -19,6 +20,7 @@
<orderEntry type="module" module-name="java-impl" />
<orderEntry type="module" module-name="java-indexing-api" />
<orderEntry type="module" module-name="smRunner" />
<orderEntry type="module" module-name="testFramework-java" scope="TEST" />
</component>
<component name="copyright">
<Base>
@@ -172,5 +174,4 @@
<option name="useAlternate" value="false" />
</LanguageOptions>
</component>
</module>
</module>
@@ -33,6 +33,7 @@ import com.intellij.psi.PsiMethod;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.Function;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
@@ -59,25 +60,28 @@ public class TestMethods extends TestMethod {
addClassesListToJavaParameters(myFailedTests, new Function<AbstractTestProxy, String>() {
@Override
public String fun(AbstractTestProxy testInfo) {
if (testInfo != null) {
final Location location = testInfo.getLocation(project, searchScope);
LOG.assertTrue(location != null);
final PsiElement element = location.getPsiElement();
if (element instanceof PsiMethod) {
final PsiClass containingClass = location instanceof MethodLocation ? ((MethodLocation)location).getContainingClass()
: ((PsiMethod)element).getContainingClass();
if (containingClass != null) {
return JavaExecutionUtil.getRuntimeQualifiedName(containingClass) + "," + testInfo.getName();
}
}
}
return null;
return testInfo != null ? getTestPresentation(testInfo, project, searchScope) : null;
}
}, data.getPackageName(), true, javaParameters);
return javaParameters;
}
@Nullable
public static String getTestPresentation(AbstractTestProxy testInfo, Project project, GlobalSearchScope searchScope) {
final Location location = testInfo.getLocation(project, searchScope);
LOG.assertTrue(location != null);
final PsiElement element = location.getPsiElement();
if (element instanceof PsiMethod) {
final PsiClass containingClass = location instanceof MethodLocation ? ((MethodLocation)location).getContainingClass()
: ((PsiMethod)element).getContainingClass();
if (containingClass != null) {
return JavaExecutionUtil.getRuntimeQualifiedName(containingClass) + "," + testInfo.getName();
}
}
return null;
}
@Override
public String suggestActionName() {
return ActionsBundle.message("action.RerunFailedTests.text");
@@ -0,0 +1,65 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit;
import com.intellij.execution.Location;
import com.intellij.execution.junit2.info.MethodLocation;
import com.intellij.execution.testframework.JavaTestLocationProvider;
import com.intellij.execution.testframework.sm.runner.SMTestProxy;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
public class JUnitRerunFailedTestsTest extends LightCodeInsightFixtureTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
myFixture.addClass("package junit.framework; public class TestCase {}");
}
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(new JavaTestLocationProvider(searchScope));
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);
}
}