@Test
  public void
      a_test_outcome_should_also_inject_issue_links_from_the_Issue_annotation_when_only_at_the_class_level() {
    TestOutcome outcome = TestOutcome.forTest("should_do_something_else", SomeTestScenario.class);

    assertThat(outcome.getFormattedIssues(), is("(#ISSUE-123)"));
  }
  private TestOutcome createScenarioOutcome(TestOutcome parameterizedOutcome) {
    TestOutcome testOutcome =
        TestOutcome.forTest(
            normalizeMethodName(parameterizedOutcome), parameterizedOutcome.getTestCase());

    return testOutcome;
  }
 @Test
 public void we_can_record_the_lifetime_of_a_test_run() throws InterruptedException {
   Thread.sleep(10);
   testOutcome.recordDuration();
   assertThat(testOutcome.getDuration(), is(greaterThanOrEqualTo(10L)));
   assertThat(testOutcome.getDuration(), is(lessThan(1000L)));
 }
Esempio n. 4
0
 /** @return The list of all the different tags in these test outcomes */
 public List<TestTag> getTags() {
   Set<TestTag> tags = Sets.newHashSet();
   for (TestOutcome outcome : outcomes) {
     tags.addAll(outcome.getTags());
   }
   return ImmutableList.copyOf(tags);
 }
  @Test
  public void should_include_the_name_of_any_screenshots_where_present() throws Exception {
    TestOutcome testOutcome = TestOutcome.forTest("a_simple_test_case", SomeTestScenario.class);
    String expectedReport =
        "<acceptance-test-run title='A simple test case' name='a_simple_test_case' steps='2' successful='1' failures='1' skipped='0' ignored='0' pending='0' result='FAILURE'>\n"
            + "  <user-story id='net.thucydides.core.reports.integration.WhenGeneratingAnXMLReport.AUserStory' name='A user story' />\n"
            + "  <test-step result='SUCCESS'>\n"
            + "    <screenshots>\n"
            + "      <screenshot image='step_1.png' source='step_1.html'/>\n"
            + "    </screenshots>\n"
            + "    <description>step 1</description>\n"
            + "  </test-step>\n"
            + "  <test-step result='FAILURE'>\n"
            + "    <description>step 2</description>\n"
            + "  </test-step>\n"
            + "</acceptance-test-run>";

    File screenshot = temporaryDirectory.newFile("step_1.png");
    File source = temporaryDirectory.newFile("step_1.html");

    TestStep step1 = TestStepFactory.successfulTestStepCalled("step 1");
    step1.addScreenshot(new ScreenshotAndHtmlSource(screenshot, source));
    testOutcome.recordStep(step1);
    testOutcome.recordStep(TestStepFactory.failingTestStepCalled("step 2"));

    File xmlReport = reporter.generateReportFor(testOutcome);
    String generatedReportText = getStringFrom(xmlReport);

    assertThat(generatedReportText, isSimilarTo(expectedReport));
  }
  @Test
  public void a_test_outcome_should_record_multiple_issues_at_class_level() {
    TestOutcome outcome =
        TestOutcome.forTest("should_do_something_else", SomeOtherTestScenario.class);

    assertThat(outcome.getFormattedIssues(), is("(#ISSUE-123, #ISSUE-456)"));
  }
Esempio n. 7
0
 /** @return The total duration of all of the tests in this set in milliseconds. */
 public Long getDuration() {
   Long total = 0L;
   for (TestOutcome outcome : outcomes) {
     total += outcome.getDuration();
   }
   return total;
 }
  @Test
  public void a_test_outcome_should_know_what_issues_there_are_in_the_title() {
    TestOutcome outcome =
        TestOutcome.forTest("should_do_this", SomeAnnotatedTestScenarioWithAnIssue.class);

    assertThat(outcome.getIssues(), hasItem("#ISSUE-123"));
  }
  @Test
  public void
      a_test_outcome_should_not_inject_issue__links_from_the_Issue_annotation_if_not_configured() {
    TestOutcome outcome = TestOutcome.forTest("should_do_this", SomeTestScenario.class);

    assertThat(outcome.getFormattedIssues(), is("(#ISSUE-123)"));
  }
 @Test
 public void should_be_able_to_add_extra_issues() {
   TestOutcome outcome = TestOutcome.forTest("should_do_this", SomeTestScenario.class);
   List<String> extraIssues = Arrays.asList("#ISSUE-456", "#ISSUE-789");
   outcome.addIssues(extraIssues);
   assertThat(outcome.getIssues(), hasItems("#ISSUE-123", "#ISSUE-456", "#ISSUE-789"));
 }
  @Test
  public void an_acceptance_test_relates_to_a_user_story() {
    net.thucydides.core.model.Story story =
        net.thucydides.core.model.Story.from(MyApp.MyUserStory.class);
    TestOutcome testOutcome = TestOutcome.forTestInStory("some_test", story);

    assertThat(testOutcome.getUserStory().getName(), is("My user story"));
  }
 private void updateResultsForAnyExternalFailures(
     TestOutcome testOutcome, TestOutcome scenarioOutcome) {
   if (rowResultsAreInconsistantWithOverallResult(testOutcome)) {
     testOutcome.getDataTable().getRows().get(0).updateResult(testOutcome.getResult());
     scenarioOutcome.addFailingExternalStep(
         new AssertionError(testOutcome.getTestFailureMessage()));
   }
 }
 private void addMethodLevelVersionsTo(List<String> versions) {
   Optional<String> version =
       TestAnnotations.forClass(testOutcome.getTestCase())
           .getAnnotatedVersionForMethod(testOutcome.getName());
   if (version.isPresent()) {
     versions.add(version.get());
   }
 }
  /** Case for easyb integration, where we use a Story class directly. */
  @Test
  public void a_test_outcome_title_should_be_the_method_name_if_no_test_class_is_defined() {
    net.thucydides.core.model.Story story = net.thucydides.core.model.Story.from(AUserStory.class);

    TestOutcome outcome = TestOutcome.forTestInStory("Some scenario", story);

    assertThat(outcome.getTitle(), is("Some scenario"));
  }
  @Test
  public void an_acceptance_test_title_is_the_title_of_the_user_story() {
    net.thucydides.core.model.Story story =
        net.thucydides.core.model.Story.from(MyApp.MyUserStory.class);
    TestOutcome testOutcome = TestOutcome.forTestInStory("some_test", story);

    assertThat(testOutcome.getStoryTitle(), is("My user story"));
  }
  @Test
  public void should_find_all_the_issues_in_a_test() {
    TestOutcome outcome =
        TestOutcome.forTest("should_do_this", SomeAnnotatedTestScenarioWithManyIssues.class);

    assertThat(
        outcome.getIssues(), hasItems("#ISSUE-123", "#ISSUE-456", "#ISSUE-100", "#ISSUE-200"));
  }
  @Test
  public void a_test_outcome_can_be_associated_with_an_issue() {
    TestOutcome outcome = TestOutcome.forTest("should_do_this", SomeAnnotatedTestScenario.class);

    outcome.isRelatedToIssue("#ISSUE-999");
    outcome.isRelatedToIssue("#ISSUE-000");
    assertThat(outcome.getIssues(), hasItems("#ISSUE-000", "#ISSUE-999"));
  }
 private void addClassLevelVersionsTo(List<String> versions) {
   String classVersion =
       TestAnnotations.forClass(testOutcome.getTestCase())
           .getAnnotatedVersionForTestCase(testOutcome.getTestCase());
   if (classVersion != null) {
     versions.add(classVersion);
   }
 }
 private String alternativeMethodName(TestOutcome testOutcome) {
   Optional<String> qualifier = testOutcome.getQualifier();
   if (qualifier.isPresent()) {
     return testOutcome.getTitle(false) + testOutcome.getQualifier().get();
   } else {
     return testOutcome.getTitle();
   }
 }
  @Test
  public void should_be_able_to_find_the_last_step() {
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 1"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 3"));

    assertThat(testOutcome.getLastStep().getDescription(), is("Step 3"));
  }
  @Test
  public void a_test_run_with_only_successful_tests_is_successful() {

    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 1"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 3"));

    assertThat(testOutcome.getResult(), is(TestResult.SUCCESS));
  }
  @Test
  public void the_acceptance_test_case_is_successful_if_all_the_tests_are_successful() {
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 1"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 3"));

    assertThat(testOutcome.getResult(), is(SUCCESS));
    assertThat(testOutcome.isSuccess(), is(true));
  }
  @Test
  public void should_list_screenshots_in_steps() {
    testOutcome.recordStep(forASuccessfulTestStepCalled("step_1"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("step_2"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("step_3"));

    assertThat(
        testOutcome.getScreenshots(), hasFilenames("step_1.png", "step_2.png", "step_3.png"));
  }
  @Test
  public void the_model_should_provide_the_number_of_successful_test_steps() {

    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 1"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 3"));

    assertThat(testOutcome.getSuccessCount(), is(3));
  }
Esempio n. 25
0
 public String getNormalizedTestNameFor(final TestOutcome testOutcome, final String qualifier) {
   String userStory = "";
   if (testOutcome.getUserStory() != null) {
     userStory = NameConverter.underscore(testOutcome.getUserStory().getName()) + "_";
   }
   String normalizedQualifier = qualifier.replaceAll(" ", "_");
   return appendSuffixTo(
       userStory + withNoArguments(testOutcome.getMethodName()) + "_" + normalizedQualifier);
 }
 @Test
 public void an_acceptance_test_records_the_original_story_class() {
   net.thucydides.core.model.Story story =
       net.thucydides.core.model.Story.from(MyApp.MyUserStory.class);
   TestOutcome testOutcome = TestOutcome.forTestInStory("some_test", story);
   assertThat(
       testOutcome.getUserStory().getUserStoryClass().getName(),
       is(MyApp.MyUserStory.class.getName()));
 }
Esempio n. 27
0
 private int totalImplementedTests() {
   int testCount = 0;
   for (TestOutcome testOutcome : testOutcomes) {
     if (!testOutcome.getTestSteps().isEmpty()) {
       testCount++;
     }
   }
   return testCount;
 }
Esempio n. 28
0
 /**
  * Return a filesystem-friendly version of the test case name. The filesytem version should have
  * no spaces and have the XML file suffix.
  */
 public String getNormalizedTestNameFor(final TestOutcome testOutcome) {
   String testName = "";
   if (testOutcome.getUserStory() != null) {
     testName = NameConverter.underscore(testOutcome.getUserStory().getName());
   }
   String scenarioName = NameConverter.underscore(testOutcome.getMethodName());
   testName = withNoIssueNumbers(withNoArguments(appendToIfNotNull(testName, scenarioName)));
   return appendSuffixTo(testName);
 }
  @Test
  public void the_acceptance_test_case_is_failing_if_multiple_tests_have_failed() {

    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 1"));
    testOutcome.recordStep(forAFailingTestStepCalled("Step 2", new AssertionError("Oh bother!")));
    testOutcome.recordStep(forAFailingTestStepCalled("Step 3", new AssertionError("Oh bother!")));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 4"));

    assertThat(testOutcome.getResult(), is(FAILURE));
  }
  @Test
  public void the_acceptance_test_case_is_ignored_if_all_test_cases_are_ignored() {

    testOutcome.recordStep(forAnIgnoredTestStepCalled("Step 1"));
    testOutcome.recordStep(forAnIgnoredTestStepCalled("Step 2"));
    testOutcome.recordStep(forAnIgnoredTestStepCalled("Step 3"));
    testOutcome.recordStep(forAnIgnoredTestStepCalled("Step 4"));

    assertThat(testOutcome.getResult(), is(IGNORED));
  }