Ejemplo n.º 1
0
  private TestEnvironment determineTestEnvironmentBasedOnTestDefaults() {
    TestEnvironment defaultEnv = null;
    TestClass defaultEnvTest = null;

    for (Test t : testsAsList()) {
      if (t instanceof TestClassWrapper) {
        if (((TestClassWrapper) t).testCount() > 0) {
          Test firstTest = ((TestClassWrapper) t).tests().nextElement();
          if (firstTest instanceof TestClass) {
            TestEnvironment env = ((TestClass) firstTest).createDefaultEnvironment();
            if (defaultEnv == null) {
              defaultEnv = env;
              defaultEnvTest = (TestClass) firstTest;
            } else {
              if (!defaultEnv.getClass().equals(env.getClass())) {
                throw new IllegalStateException(
                    "The test "
                        + defaultEnvTest.getClassName()
                        + " requires the "
                        + defaultEnv.getClass()
                        + " environment, while the "
                        + ((TestClass) firstTest).getClassName()
                        + " test requires the "
                        + env.getClass()
                        + " environment.  Automatic resolution of the appropriate "
                        + "test environment will only work if all tests in the suite use the exact same default test environment.");
              }
            }
          } else {
            throw new IllegalStateException(
                "Found a test that was a " + firstTest.getClass() + " instead of a TestClass");
          }
        } else {
          throw new IllegalStateException(
              "Found a test class "
                  + ((TestClassWrapper) t).getBackingType().getName()
                  + " that has no tests.");
        }
      } else {
        throw new IllegalStateException(
            "Found a test that was a " + t.getClass() + " instead of a TestClassWrapper");
      }
    }

    return defaultEnv;
  }
Ejemplo n.º 2
0
  private void maybeCreateTestClassWrappers() {

    maybeInitSuite();

    if (!_testClassWrappersCreated) {
      long start = System.currentTimeMillis();

      if (_testSpecs.isEmpty()) {
        TestClassFinder finder =
            new TestClassFinder(_iFileFilters, _packageFilters, _withPackages, _typeFilters);
        _testSpecs.addAll(finder.findTests(_gosuClassSearchPath, _javaClassSearchPath));
      }

      restrictTestSpecsToSpecifiedNames();

      for (TestSpec spec : _testSpecs) {
        if (_testEnvironment.isRemoteExecutionEnvironment()) {
          String[] methods = spec.runAllMethods() ? null : spec.getMethods();
          RemoteTestClassWrapper remoteWrapper =
              new RemoteTestClassWrapper(_executionManager, spec.getTestTypeName(), methods);
          addTest(remoteWrapper);
        } else {
          IType type = spec.getTestType();
          addTest(new TestClassWrapper(_executionManager, type, spec.getMethods()));
        }
      }
      _testClassWrappersCreated = true;
      long end = System.currentTimeMillis();
      System.out.println("Test wrappers created in " + (end - start) + "ms");

      if (_testEnvironment.isDynamicallyDeterminedEnvironment()) {
        _testEnvironment = determineTestEnvironmentBasedOnTestDefaults();
        System.out.println(
            "Dynamically determined the test environment to be " + _testEnvironment.getClass());
        // This is pretty hacky, but RemoteTestEnvironments need a chance to tell the remote server
        // what sort of environment to set up, and that actually needs to be done prior to beginning
        // the suite
        if (_testEnvironment instanceof ForwardingTestEnvironment) {
          _testEnvironment.initializeTypeSystem();
        }
        _executionManager.setEnvironment(_testEnvironment);
      }
    }
  }