diff --git a/platform/platform-impl/testSrc/com/intellij/ide/plugins/VersionCompareTest.java b/platform/platform-impl/testSrc/com/intellij/ide/plugins/VersionCompareTest.java index 59ad9f7437fb..c830d138674f 100644 --- a/platform/platform-impl/testSrc/com/intellij/ide/plugins/VersionCompareTest.java +++ b/platform/platform-impl/testSrc/com/intellij/ide/plugins/VersionCompareTest.java @@ -27,10 +27,6 @@ import junit.framework.TestSuite; * To change this template use Options | File Templates. */ public class VersionCompareTest extends TestCase { - public static TestSuite suite () { - return new TestSuite (VersionCompareTest.class); - } - public void testEqual () { String v1 = "0.0.1"; String v2 = "0.0.1"; diff --git a/platform/testFramework/src/com/intellij/TestAll.java b/platform/testFramework/src/com/intellij/TestAll.java index f522cebb64b5..e21d4140dec1 100644 --- a/platform/testFramework/src/com/intellij/TestAll.java +++ b/platform/testFramework/src/com/intellij/TestAll.java @@ -31,6 +31,10 @@ import com.intellij.testFramework.*; import com.intellij.tests.ExternalClasspathClassLoader; import com.intellij.util.ArrayUtil; import junit.framework.*; +import org.jetbrains.annotations.Nullable; +import org.junit.runner.Description; +import org.junit.runner.manipulation.Filter; +import org.junit.runner.manipulation.NoTestsRemainException; import java.io.File; import java.io.IOException; @@ -62,9 +66,37 @@ public class TestAll implements Test { private static final int FILTER_CLASSES = 16; public static int ourMode = SAVE_MEMORY_SNAPSHOT /*| START_GUARD | RUN_GC | CHECK_MEMORY*/ | FILTER_CLASSES; + private static final boolean PERFORMANCE_TESTS_ONLY = System.getProperty(TestCaseLoader.PERFORMANCE_TESTS_ONLY_FLAG) != null; private int myLastTestTestMethodCount = 0; public static final int MAX_FAILURE_TEST_COUNT = 150; + private static final Filter PERFORMANCE_ONLY = new Filter() { + @Override + public boolean shouldRun(Description description) { + String className = description.getClassName(); + String methodName = description.getMethodName(); + return className != null && hasPerformance(className) || + methodName != null && hasPerformance(methodName); + } + + @Override + public String describe() { + return "Performance Tests Only"; + } + }; + + private static final Filter NO_PERFORMANCE = new Filter() { + @Override + public boolean shouldRun(Description description) { + return !PERFORMANCE_ONLY.shouldRun(description); + } + + @Override + public String describe() { + return "All Except Performance"; + } + }; + @Override public int countTestCases() { List classes = myTestCaseLoader.getClasses(); @@ -247,16 +279,36 @@ public class TestAll implements Test { return realFreeMemory < needed; } - private static Test getTest(Class testCaseClass) { + private static boolean isPerformanceTestsRun() { + return PERFORMANCE_TESTS_ONLY; + } + + @Nullable + private static Test getTest(final Class testCaseClass) { if ((testCaseClass.getModifiers() & Modifier.PUBLIC) == 0) return null; - try { - Method suiteMethod = testCaseClass.getMethod("suite", ArrayUtil.EMPTY_CLASS_ARRAY); - return (Test)suiteMethod.invoke(null, ArrayUtil.EMPTY_CLASS_ARRAY); + Method suiteMethod = safeFindMethod(testCaseClass, "suite"); + if (suiteMethod != null && !isPerformanceTestsRun()) { + try { + return (Test)suiteMethod.invoke(null, ArrayUtil.EMPTY_CLASS_ARRAY); + } + catch (Exception e) { + System.err.println("Failed to execute suite ()"); + e.printStackTrace(); + } } - catch (NoSuchMethodException e) { + else { if (TestRunnerUtil.isJUnit4TestClass(testCaseClass)) { - return new JUnit4TestAdapter(testCaseClass); + JUnit4TestAdapter adapter = new JUnit4TestAdapter(testCaseClass); + if (!hasPerformance(testCaseClass.getSimpleName()) || !isPerformanceTestsRun()) { + try { + adapter.filter(isPerformanceTestsRun() ? PERFORMANCE_ONLY : NO_PERFORMANCE); + } + catch (NoTestsRemainException e1) { + // Ignore + } + } + return adapter; } return new TestSuite(testCaseClass){ @Override @@ -264,6 +316,8 @@ public class TestAll implements Test { if (!(test instanceof TestCase)) { super.addTest(test); } else { + if (isPerformanceTestsRun() ^ (hasPerformance(((TestCase)test).getName()) || hasPerformance(testCaseClass.getSimpleName()))) return; + Method method = findTestMethod((TestCase)test); if (method == null || !TestCaseLoader.isBombed(method)) { super.addTest(test); @@ -272,24 +326,30 @@ public class TestAll implements Test { } + @Nullable private Method findTestMethod(final TestCase testCase) { - try { - return testCase.getClass().getMethod(testCase.getName()); - } - catch (NoSuchMethodException e1) { - return null; - } + return safeFindMethod(testCase.getClass(), testCase.getName()); } }; } - catch (Exception e) { - System.err.println("Failed to execute suite ()"); - e.printStackTrace(); - } return null; } + private static boolean hasPerformance(String name) { + return name.toLowerCase().contains("performance"); + } + + @Nullable + private static Method safeFindMethod(Class klass, String name) { + try { + return klass.getMethod(name); + } + catch (NoSuchMethodException e) { + return null; + } + } + public static String[] getClassRoots() { String testRoots = System.getProperty("test.roots"); if (testRoots != null) { @@ -325,7 +385,7 @@ public class TestAll implements Test { if (Boolean.parseBoolean(System.getProperty("idea.ignore.predefined.groups")) || (ourMode & FILTER_CLASSES) == 0) { classFilterName = ""; } - myTestCaseLoader = new TestCaseLoader(classFilterName); + myTestCaseLoader = new TestCaseLoader(classFilterName, isPerformanceTestsRun()); myTestCaseLoader.addFirstTest(Class.forName("_FirstInSuiteTest")); myTestCaseLoader.addLastTest(Class.forName("_LastInSuiteTest")); @@ -348,7 +408,6 @@ public class TestAll implements Test { } log("Number of test classes found: " + testCaseLoader.getClasses().size()); - testCaseLoader.checkClassesExist(); } private static void log(String message) { diff --git a/platform/testFramework/src/com/intellij/TestCaseLoader.java b/platform/testFramework/src/com/intellij/TestCaseLoader.java index 7ad2b70a33b9..816161729755 100644 --- a/platform/testFramework/src/com/intellij/TestCaseLoader.java +++ b/platform/testFramework/src/com/intellij/TestCaseLoader.java @@ -25,8 +25,6 @@ package com.intellij; import com.intellij.idea.Bombed; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.TestRunnerUtil; @@ -39,7 +37,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.*; -@SuppressWarnings({"HardCodedStringLiteral"}) +@SuppressWarnings({"HardCodedStringLiteral", "UseOfSystemOutOrSystemErr", "CallToPrintStackTrace", "TestOnlyProblems"}) public class TestCaseLoader { /** Holds name of JVM property that is assumed to define target test group name. */ @@ -48,28 +46,31 @@ public class TestCaseLoader { /** Holds name of JVM property that is assumed to define filtering rules for test classes. */ private static final String TARGET_TEST_PATTERNS = "idea.test.patterns"; - /** Holds name of JVM property that is assumed to determine if only 'fast' tests should be executed. */ - private static final String FAST_TESTS_ONLY_FLAG = "idea.fast.only"; + public static final String PERFORMANCE_TESTS_ONLY_FLAG = "idea.performance.tests"; private final List myClassList = new ArrayList(); private Class myFirstTestClass; private Class myLastTestClass; private final TestClassesFilter myTestClassesFilter; - private final String myTestGroupName; - private final Set blockedTests = new HashSet(); - private final String[] slowTestNames; + private boolean myIsPerformanceTestsRun; public TestCaseLoader(String classFilterName) { + this(classFilterName, false); + } + + public TestCaseLoader(String classFilterName, boolean isPerformanceTestsRun) { + myIsPerformanceTestsRun = isPerformanceTestsRun; InputStream excludedStream = StringUtil.isEmpty(classFilterName) ? null : getClass().getClassLoader().getResourceAsStream(classFilterName); String preconfiguredGroup = System.getProperty(TARGET_TEST_GROUP); - if (preconfiguredGroup == null || "".equals(preconfiguredGroup.trim())) { - myTestGroupName = ""; + String testGroupName; + if (preconfiguredGroup == null || preconfiguredGroup.trim().isEmpty()) { + testGroupName = ""; } else { - myTestGroupName = preconfiguredGroup.trim(); + testGroupName = preconfiguredGroup.trim(); } if (excludedStream != null) { try { - myTestClassesFilter = GroupBasedTestClassFilter.createOn(new InputStreamReader(excludedStream), myTestGroupName); + myTestClassesFilter = GroupBasedTestClassFilter.createOn(new InputStreamReader(excludedStream), testGroupName); } finally { try { @@ -90,40 +91,7 @@ public class TestCaseLoader { } } - String[] names; - try { - InputStream stream = getClass().getClassLoader().getResourceAsStream("tests/slowTests.txt"); - names = FileUtil.loadTextAndClose(new InputStreamReader(stream)).split("\\s"); - } - catch (Exception e) { - // no luck - names = new String[0]; - } - slowTestNames = names; - if (Comparing.equal(System.getProperty(FAST_TESTS_ONLY_FLAG), "true")) { - blockedTests.addAll(Arrays.asList(slowTestNames)); - } - else { - checkClassesExist(); - } - System.out.println("Using test group: [" + myTestGroupName +"]"); - } - - void checkClassesExist() { - String s = ""; - for (String slowTestName : slowTestNames) { - if (slowTestName.trim().length() == 0) continue; - if (blockedTests.contains(slowTestName)) continue; - try { - Class.forName(slowTestName); - } - catch (ClassNotFoundException e) { - s += "\n" + slowTestName; - } - } - if (s.length() != 0) { - throw new RuntimeException("Tests in slowTests.txt which cannot be instantiated: "+s); - } + System.out.println("Using test group: [" + testGroupName +"]"); } /* @@ -165,7 +133,10 @@ public class TestCaseLoader { //System.out.println("testCaseClass = " + testCaseClass); return true; } - } catch (NoSuchMethodException e) { } + } + catch (NoSuchMethodException e) { + // can't be + } return TestRunnerUtil.isJUnit4TestClass(testCaseClass); } @@ -174,8 +145,10 @@ public class TestCaseLoader { * Determine if we should exclude this test case. */ private boolean shouldExcludeTestClass(Class testCaseClass) { - return !myTestClassesFilter.matches(testCaseClass.getName()) || isBombed(testCaseClass) - || blockedTests.contains(testCaseClass.getName()); + String className = testCaseClass.getName(); + if (className.toLowerCase().contains("performance") && !myIsPerformanceTestsRun) return true; + + return !myTestClassesFilter.matches(className) || isBombed(testCaseClass); } public static boolean isBombed(final Method method) {