public void testPrintSummaryFalseWithoutRedirect() {
   final OutputValidator outputValidator =
       unpack().redirectToFile(false).printSummary(false).executeTest();
   outputValidator
       .getSurefireReportsFile("forkConsoleOutput.Test1-output.txt")
       .assertFileNotExists();
 }
 @Test
 public void wrongClassloaderUSedInSmartStacktraceparser() throws Exception {
   OutputValidator outputValidator =
       unpack("surefire-979-smartStackTrace-wrongClassloader").failNever().executeTest();
   outputValidator.verifyTextInLog(
       "java.lang.NoClassDefFoundError: org/apache/commons/io/input/AutoCloseInputStream");
 }
 @Test
 public void testBuildFailingWhenErrors() {
   OutputValidator outputValidator =
       unpack("/surefire-500-puzzling-error").failNever().executeTest();
   TestFile surefireReportsFile =
       outputValidator.getSurefireReportsFile("surefire500.ExplodingTest.txt");
   surefireReportsFile.assertContainsText("java.lang.NoClassDefFoundError: whoops!");
 }
 @Test
 public void testNGRunCategoryAB() {
   OutputValidator validator =
       unpackTestNG().groups("CategoryA AND CategoryB").debugLogging().executeTest();
   validator.verifyErrorFreeLog();
   validator.assertTestSuiteResults(2, 0, 0, 0);
   validator.verifyTextInLog("BasicTest.testInCategoriesAB()");
   validator.verifyTextInLog("CategoryCTest.testInCategoriesAB()");
 }
예제 #5
0
 @Test
 public void properNewlines() {
   final OutputValidator outputValidator =
       unpack("/consoleOutput").redirectToFile(true).setJUnitVersion("4.7").executeTest();
   TestFile surefireReportsFile =
       outputValidator.getSurefireReportsFile("consoleOutput.Test1-output.txt");
   surefireReportsFile.assertContainsText("SoutAgain");
   surefireReportsFile.assertContainsText("Printline in shutdown hook");
 }
 public void testPrintSummaryFalseWithRedirect() {
   final OutputValidator outputValidator =
       unpack()
           .redirectToFile(true)
           .printSummary(false)
           .debugLogging()
           .showErrorStackTraces()
           .executeTest();
   outputValidator.getSurefireReportsFile("forkConsoleOutput.Test1-output.txt").assertFileExists();
 }
 @Test
 public void testReportWithoutAggregate() throws Exception {
   SurefireLauncher surefireLauncher = unpack().failNever();
   surefireLauncher.executeTest();
   surefireLauncher.reset();
   surefireLauncher.executeSurefireReport();
   OutputValidator module1 = surefireLauncher.getSubProjectValidator("module1");
   TestFile siteFile = module1.getSiteFile("surefire-report.html");
   siteFile.assertContainsText("MyModule1ClassTest");
   siteFile.assertContainsText("MyDummyClassM1Test");
 }
  @Test
  public void testReportWithAggregate() throws Exception {

    SurefireLauncher surefireLauncher = unpack().failNever();
    surefireLauncher.executeTest();
    surefireLauncher.addGoal("-Daggregate=true");
    OutputValidator validator = surefireLauncher.executeSurefireReport();
    TestFile siteFile = validator.getSiteFile("surefire-report.html");
    siteFile.assertContainsText("MyModule1ClassTest");
    siteFile.assertContainsText("MyModule2ClassTest");
    siteFile.assertContainsText("MyDummyClassM1Test");
  }
 @Test
 public void testNGRunCategoryNotC() {
   OutputValidator validator = unpackTestNG().groups("!CategoryC").debugLogging().executeTest();
   validator.verifyErrorFreeLog();
   validator.assertTestSuiteResults(8, 0, 0, 0);
   validator.verifyTextInLog("catA: 2");
   validator.verifyTextInLog("catB: 2");
   validator.verifyTextInLog("catC: 0");
   validator.verifyTextInLog("catNone: 1");
   validator.verifyTextInLog("mA: 2");
   validator.verifyTextInLog("mB: 2");
   validator.verifyTextInLog("mC: 0");
   validator.verifyTextInLog("NoCategoryTest.CatNone: 1");
 }
  @Test
  public void testMethodsParallelWithSuite() throws VerificationException {
    OutputValidator validator = unpack().executeTest().verifyErrorFree(6);
    Set<String> testLines = printTestLines(validator, "test finished after duration=");
    assertThat(testLines.size(), is(2));
    for (String testLine : testLines) {
      long duration = duration(testLine);
      long min = 250 * PERFORMANCE_TEST_MULTIPLICATION_FACTOR;
      long max = 750 * PERFORMANCE_TEST_MULTIPLICATION_FACTOR;
      assertTrue(
          format("duration %d should be between %d and %d ms", duration, min, max),
          duration > min && duration < max);
    }
    Set<String> suiteLines = printTestLines(validator, "suite finished after duration=");
    assertThat(suiteLines.size(), is(1));
    long duration = duration(suiteLines.iterator().next());
    long min = 750 * PERFORMANCE_TEST_MULTIPLICATION_FACTOR;
    long max = 1250 * PERFORMANCE_TEST_MULTIPLICATION_FACTOR;
    assertTrue(
        format("duration %d should be between %d and %d ms", duration, min, max),
        duration > min && duration < max);

    String delayMin =
        lowerScaleFormatter.format(0.98 * PERFORMANCE_TEST_MULTIPLICATION_FACTOR * 0.5);
    String delayMax =
        noFractionalDigitsFormatter.format(PERFORMANCE_TEST_MULTIPLICATION_FACTOR * 0.5) + ".";

    for (String line : validator.loadLogLines()) {
      if (line.startsWith("Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed:")) {
        assertThat(
            line,
            anyOf( // 1.9xx to 2.xxx can vary depending on CI jobs
                containsString("Time elapsed: " + delayMin),
                containsString("Time elapsed: " + delayMax)));
        assertThat(
            line,
            anyOf(
                endsWith(" s - in surefire747.SuiteTest1"),
                endsWith(" s - in surefire747.SuiteTest2")));
      }
    }
  }
 private static Set<String> printTestLines(OutputValidator validator, String pattern)
     throws VerificationException {
   Set<String> log = new TreeSet<String>(validator.loadLogLines());
   for (Iterator<String> it = log.iterator(); it.hasNext(); ) {
     String line = it.next();
     if (!line.contains(pattern)) {
       it.remove();
     }
   }
   return log;
 }
 @Test
 public void categoryAB() {
   OutputValidator validator =
       unpackJUnit().groups("junit4.CategoryA AND junit4.CategoryB").executeTest();
   validator.verifyErrorFreeLog();
   validator.assertTestSuiteResults(2, 0, 0, 0);
   validator.verifyTextInLog("catA: 1");
   validator.verifyTextInLog("catB: 1");
   validator.verifyTextInLog("catC: 0");
   validator.verifyTextInLog("catNone: 0");
   validator.verifyTextInLog("mA: 1");
   validator.verifyTextInLog("mB: 1");
   validator.verifyTextInLog("mC: 0");
 }
 @Test
 public void testExcludedGroups() {
   OutputValidator validator = unpackJUnit().setExcludedGroups("junit4.CategoryC").executeTest();
   validator.verifyErrorFreeLog();
   validator.assertTestSuiteResults(5, 0, 0, 0);
   validator.verifyTextInLog("catA: 2");
   validator.verifyTextInLog("catB: 2");
   validator.verifyTextInLog("catC: 0");
   validator.verifyTextInLog("catNone: 1");
   validator.verifyTextInLog("NoCategoryTest.CatNone: 1");
 }