예제 #1
0
  private void monitorTestSuite(TestSuite testSuite) {
    testSuite.addTestSuiteListener(testSuiteListener);

    for (int j = 0; j < testSuite.getTestCaseCount(); j++) {
      monitorTestCase(testSuite.getTestCaseAt(j));
    }
  }
예제 #2
0
  private void unmonitorTestSuite(TestSuite testSuite) {
    testSuite.removeTestSuiteListener(testSuiteListener);

    for (int j = 0; j < testSuite.getTestCaseCount(); j++) {
      TestCase testCase = testSuite.getTestCaseAt(j);
      unmonitorTestCase(testCase);
    }
  }
예제 #3
0
  @Override
  public boolean runRunner() throws Exception {
    AnalyticsHelper.initializeAnalytics();
    Analytics.trackSessionStart();

    initGroovyLog();

    assertions.clear();

    String projectFile = getProjectFile();

    WsdlProject project =
        (WsdlProject)
            ProjectFactoryRegistry.getProjectFactory("wsdl")
                .createNew(projectFile, getProjectPassword());

    if (project.isDisabled()) {
      throw new Exception("Failed to load SoapUI project file [" + projectFile + "]");
    }

    initProject(project);
    ensureOutputFolder(project);

    if (this.printAlertSiteReport) {
      testCaseRunLogReport = new TestCaseRunLogReport(getAbsoluteOutputFolder(project));
    }

    log.info("Running SoapUI tests in project [" + project.getName() + "]");

    long startTime = System.nanoTime();

    List<TestCase> testCasesToRun = new ArrayList<TestCase>();

    // validate testSuite argument
    if (testSuite != null && project.getTestSuiteByName(testSuite) == null) {
      throw new Exception(
          "TestSuite with name ["
              + testSuite
              + "] is missing in Project ["
              + project.getName()
              + "]");
    }

    // start by listening to all testcases.. (since one testcase can call
    // another)
    for (int c = 0; c < project.getTestSuiteCount(); c++) {
      TestSuite suite = project.getTestSuiteAt(c);
      for (int i = 0; i < suite.getTestCaseCount(); i++) {
        TestCase tc = suite.getTestCaseAt(i);
        if ((testSuite == null || suite.getName().equals(testSuite))
            && testCase != null
            && tc.getName().equals(testCase)) {
          testCasesToRun.add(tc);
        }

        addListeners(tc);
      }
    }

    try {
      // validate testSuite argument
      if (testCase != null && testCasesToRun.size() == 0) {
        if (testSuite == null) {
          throw new Exception(
              "TestCase with name ["
                  + testCase
                  + "] is missing in Project ["
                  + project.getName()
                  + "]");
        } else {
          throw new Exception(
              "TestCase with name ["
                  + testCase
                  + "] in TestSuite ["
                  + testSuite
                  + "] is missing in Project ["
                  + project.getName()
                  + "]");
        }
      }

      // decide what to run
      if (testCasesToRun.size() > 0) {
        for (TestCase testCase : testCasesToRun) {
          runTestCase((WsdlTestCase) testCase);
        }
      } else if (testSuite != null) {
        WsdlTestSuite ts = project.getTestSuiteByName(testSuite);
        if (ts == null) {
          throw new Exception("TestSuite with name [" + testSuite + "] not found in project");
        } else {
          runSuite(ts);
        }
      } else {
        runProject(project);
      }

      long timeTaken = (System.nanoTime() - startTime) / 1000000;

      if (printReport) {
        printReport(timeTaken);
      }

      exportReports(project);

      if (saveAfterRun && !project.isRemote()) {
        try {
          project.save();
        } catch (Throwable t) {
          log.error("Failed to save project", t);
        }
      }

      if ((assertions.size() > 0 || failedTests.size() > 0) && !ignoreErrors) {
        throwFailureException();
      }

      return true;
    } finally {
      for (int c = 0; c < project.getTestSuiteCount(); c++) {
        TestSuite suite = project.getTestSuiteAt(c);
        for (int i = 0; i < suite.getTestCaseCount(); i++) {
          TestCase tc = suite.getTestCaseAt(i);
          removeListeners(tc);
        }
      }
    }
  }