public static TestSuite suite() {
   // we create a test suite containing a test for every AbstractFutureTest test method and we
   // set it as the name of the test.  Then in runTest we can reflectively load and invoke the
   // corresponding method on AbstractFutureTest in the correct classloader.
   TestSuite suite = new TestSuite(AbstractFutureFallbackAtomicHelperTest.class.getName());
   for (Method method : AbstractFutureTest.class.getDeclaredMethods()) {
     if (Modifier.isPublic(method.getModifiers()) && method.getName().startsWith("test")) {
       suite.addTest(
           TestSuite.createTest(AbstractFutureFallbackAtomicHelperTest.class, method.getName()));
     }
   }
   return suite;
 }
  private CombinationTestSupport[] getCombinations() {
    try {
      Method method = getClass().getMethod("initCombos", (Class[]) null);
      method.invoke(this, (Object[]) null);
    } catch (Throwable e) {
    }

    String name = getName().split(" ")[0];
    String comboSetupMethodName =
        "initCombosFor" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
    try {
      Method method = getClass().getMethod(comboSetupMethodName, (Class[]) null);
      method.invoke(this, (Object[]) null);
    } catch (Throwable e) {
    }

    try {
      ArrayList<HashMap<String, Object>> expandedOptions = new ArrayList<HashMap<String, Object>>();
      expandCombinations(new ArrayList<ComboOption>(comboOptions.values()), expandedOptions);

      if (expandedOptions.isEmpty()) {
        combosEvaluated = true;
        return new CombinationTestSupport[] {this};
      } else {

        ArrayList<CombinationTestSupport> result = new ArrayList<CombinationTestSupport>();
        // Run the test case for each possible combination
        for (Iterator<HashMap<String, Object>> iter = expandedOptions.iterator();
            iter.hasNext(); ) {
          CombinationTestSupport combo =
              (CombinationTestSupport) TestSuite.createTest(getClass(), name);
          combo.combosEvaluated = true;
          combo.setOptions(iter.next());
          result.add(combo);
        }

        CombinationTestSupport rc[] = new CombinationTestSupport[result.size()];
        result.toArray(rc);
        return rc;
      }
    } catch (Throwable e) {
      combosEvaluated = true;
      return new CombinationTestSupport[] {this};
    }
  }
  public static Test suite(Class<? extends CombinationTestSupport> clazz) {
    TestSuite suite = new TestSuite();

    ArrayList<String> names = new ArrayList<String>();
    Method[] methods = clazz.getMethods();
    for (int i = 0; i < methods.length; i++) {
      String name = methods[i].getName();
      if (names.contains(name) || !isPublicTestMethod(methods[i])) {
        continue;
      }
      names.add(name);
      Test test = TestSuite.createTest(clazz, name);
      if (test instanceof CombinationTestSupport) {
        CombinationTestSupport[] combinations = ((CombinationTestSupport) test).getCombinations();
        for (int j = 0; j < combinations.length; j++) {
          suite.addTest(combinations[j]);
        }
      } else {
        suite.addTest(test);
      }
    }
    return suite;
  }
  private void addTestsFromFile(TestSuite suite, File file) {
    Class<?> rawClass = getClassFrom(file);
    if (rawClass == null || !TestCase.class.isAssignableFrom(rawClass)) {
      return;
    }

    @SuppressWarnings("unchecked")
    Class<? extends TestCase> clazz = (Class<? extends TestCase>) rawClass;

    int modifiers = clazz.getModifiers();

    if (Modifier.isAbstract(modifiers) || !Modifier.isPublic(modifiers)) {
      return;
    }

    if (onlyRun.size() > 0 && !onlyRun.contains(rawClass.getSimpleName())) {
      return;
    }

    if (isIgnored(clazz)) {
      System.err.println(
          "Ignoring test class: " + clazz + ": " + clazz.getAnnotation(Ignore.class).reason());
      return;
    }

    if (!withDriver && NeedsDriver.class.isAssignableFrom(clazz)) {
      return;
    }

    boolean include = true;
    if (patterns.size() > 0) {
      include = false;
      for (String pattern : patterns) {
        include |= clazz.getName().matches(pattern);
      }
    }
    if (!include) {
      return;
    }

    for (String excludePattern : excludePatterns) {
      if (clazz.getName().matches(excludePattern)) {
        return;
      }
    }

    Method[] methods = clazz.getMethods();
    for (Method method : methods) {
      if (isTestMethod(method)) {
        Test test = TestSuite.createTest(clazz, method.getName());
        if (test instanceof NeedsDriver) {
          boolean freshDriver = false;
          if (method.isAnnotationPresent(NeedsFreshDriver.class)) {
            freshDriver = true;
          }

          boolean restartDriver = false;
          if (method.isAnnotationPresent(NoDriverAfterTest.class)) {
            restartDriver = true;
          }

          if (withDriver) {
            test =
                new DriverTestDecorator(test, driverClass, keepDriver, freshDriver, restartDriver);
          }
        }
        if (outputTestNames) {
          test = new TestNameDecorator(test);
        }
        suite.addTest(test);
      }
    }
  }
Beispiel #5
0
 protected TestResult runSingleMethod(String testCase, String method, boolean wait)
     throws Exception {
   Class<? extends TestCase> testClass = loadSuiteClass(testCase);
   Test test = TestSuite.createTest(testClass, method);
   return doRun(test, wait);
 }