コード例 #1
0
  @Test
  public void should_record_minimal_nested_test_steps_as_nested_structures() throws Exception {
    TestOutcome testOutcome =
        TestOutcome.forTest("a_nested_test_case", SomeNestedTestScenario.class);
    String expectedReport =
        "<acceptance-test-run title='A nested test case' name='a_nested_test_case' steps='1' successful='1' failures='0' skipped='0' ignored='0' pending='0' result='SUCCESS'>\n"
            + "  <user-story id='net.thucydides.core.reports.integration.WhenGeneratingAnXMLReport.AUserStory' name='A user story' />\n"
            + "  <test-group name='Group 1' result='SUCCESS'>\n"
            + "    <test-group name='Group 1.1' result='SUCCESS'>\n"
            + "      <test-group name='Group 1.1.1' result='SUCCESS'>\n"
            + "        <test-step result='SUCCESS'>\n"
            + "          <description>step 1</description>\n"
            + "        </test-step>\n"
            + "      </test-group>\n"
            + "    </test-group>\n"
            + "  </test-group>\n"
            + "</acceptance-test-run>";

    testOutcome.startGroup("Group 1");
    testOutcome.startGroup("Group 1.1");
    testOutcome.startGroup("Group 1.1.1");
    testOutcome.recordStep(TestStepFactory.successfulTestStepCalled("step 1"));
    testOutcome.endGroup();
    testOutcome.endGroup();
    testOutcome.endGroup();

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

    assertThat(generatedReportText, isSimilarTo(expectedReport));
  }
コード例 #2
0
  @Test
  public void the_report_should_list_test_groups_as_headings_in_the_table() throws Exception {

    TestOutcome testOutcome = new TestOutcome("a_simple_test_case");

    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 0"));
    testOutcome.startGroup("A group");
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 1"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 3"));
    testOutcome.startGroup("Another group");
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 4"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 5"));
    testOutcome.startGroup("Yet another group");
    testOutcome.recordStep(forAnIgnoredTestStepCalled("Step 6"));
    testOutcome.endGroup();
    testOutcome.recordStep(forABrokenTestStepCalled("Step 7", new AssertionError("Oh bother!")));
    testOutcome.recordStep(forABrokenTestStepCalled("Step 8", new AssertionError("Oh bother!")));
    testOutcome.recordStep(forASkippedTestStepCalled("Step 9"));
    testOutcome.recordStep(forAPendingTestStepCalled("Step 10"));
    testOutcome.recordStep(forAPendingTestStepCalled("Step 11"));
    testOutcome.recordStep(forAPendingTestStepCalled("Step 12"));
    testOutcome.endGroup();
    testOutcome.recordStep(forAPendingTestStepCalled("Step 13"));
    testOutcome.recordStep(forAPendingTestStepCalled("Step 14"));
    testOutcome.endGroup();
    testOutcome.recordStep(forASkippedTestStepCalled("Step 15"));

    reporter.setOutputDirectory(new File("target/thucyidides"));
    reporter.generateReportFor(testOutcome, allTestOutcomes);
  }
コード例 #3
0
  @Test
  public void should_be_able_to_find_the_last_step_in_a_group() {

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

    assertThat(testOutcome.getLastStep().getDescription(), is("Step 3"));
  }
コード例 #4
0
  @Test
  public void a_test_run_with_a_nested_group_containing_a_failure_is_a_failure() {
    testOutcome.startGroup("A group");
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 1"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 3"));
    testOutcome.startGroup("Another group");
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 4"));
    testOutcome.recordStep(forAFailingTestStepCalled("Step 5", new AssertionError("Oh bother!")));
    testOutcome.endGroup();
    testOutcome.endGroup();

    assertThat(testOutcome.getResult(), is(TestResult.FAILURE));
  }
コード例 #5
0
 private void createNestedTestSteps() {
   testOutcome.recordStep(forASuccessfulTestStepCalled("Step 0"));
   testOutcome.recordStep(forASuccessfulTestStepCalled("A group"));
   testOutcome.startGroup();
   testOutcome.recordStep(forASuccessfulTestStepCalled("Step 1"));
   testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2"));
   testOutcome.recordStep(forASuccessfulTestStepCalled("Step 3"));
   testOutcome.recordStep(forASuccessfulTestStepCalled("Another group"));
   testOutcome.startGroup();
   testOutcome.recordStep(forASuccessfulTestStepCalled("Step 4"));
   testOutcome.recordStep(forASuccessfulTestStepCalled("Step 5"));
   testOutcome.endGroup();
   testOutcome.endGroup();
 }
コード例 #6
0
  @Test
  public void should_count_deeply_nested_test_steps() {
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 1"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2"));
    testOutcome.startGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2.1"));
    testOutcome.startGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2.1.1"));
    testOutcome.startGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2.1.1.1"));
    testOutcome.endGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2.1.2"));
    testOutcome.endGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2.2"));
    testOutcome.endGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 3"));

    assertThat(testOutcome.getNestedStepCount(), is(8));
  }
コード例 #7
0
  @Test
  public void an_acceptance_test_run_can_contain_steps_nested_in_step_groups() {
    testOutcome.recordStep(forASuccessfulTestStepCalled("A Group"));
    testOutcome.startGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 1"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 3"));
    testOutcome.endGroup();

    assertThat(testOutcome.getTestSteps().size(), is(1));
  }
コード例 #8
0
  @Test
  public void a_test_group_with_only_ignored_tests_is_ignored() {

    testOutcome.startGroup("A group");
    testOutcome.recordStep(forAnIgnoredTestStepCalled("Step 1"));
    testOutcome.recordStep(forAnIgnoredTestStepCalled("Step 2"));
    testOutcome.recordStep(forAnIgnoredTestStepCalled("Step 3"));
    testOutcome.endGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 4"));

    TestStep aGroup = testOutcome.getTestSteps().get(0);
    assertThat(aGroup.getResult(), is(TestResult.IGNORED));
  }
コード例 #9
0
  @Test
  public void a_test_group_with_a_pending_test_is_pending() {

    testOutcome.startGroup("A group");
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 1"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2"));
    testOutcome.recordStep(forAPendingTestStepCalled("Step 3"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 4"));
    testOutcome.endGroup();

    TestStep aGroup = testOutcome.getTestSteps().get(0);
    assertThat(aGroup.getResult(), is(TestResult.PENDING));
  }
コード例 #10
0
  @Test
  public void a_test_group_with_only_successful_tests_is_successful() {

    testOutcome.recordStep(forASuccessfulTestStepCalled("A group"));
    testOutcome.startGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 1"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 3"));
    testOutcome.endGroup();

    TestStep aGroup = testOutcome.getTestSteps().get(0);
    assertThat(aGroup.getResult(), is(TestResult.SUCCESS));
  }
コード例 #11
0
 private void createNestedTestRun() {
   testOutcome.recordStep(forASuccessfulTestStepCalled("Step 0"));
   testOutcome.recordStep(forASuccessfulTestStepCalled("A group"));
   testOutcome.startGroup();
   testOutcome.recordStep(forASuccessfulTestStepCalled("Step 1"));
   testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2"));
   testOutcome.recordStep(forASuccessfulTestStepCalled("Step 3"));
   testOutcome.recordStep(forAFailingTestStepCalled("Step 7", new AssertionError("Oh bother!")));
   testOutcome.recordStep(forAPendingTestStepCalled("Step 10"));
   testOutcome.recordStep(forASuccessfulTestStepCalled("Another group"));
   testOutcome.startGroup();
   testOutcome.recordStep(forASuccessfulTestStepCalled("Step 4"));
   testOutcome.recordStep(forASuccessfulTestStepCalled("Step 5"));
   testOutcome.recordStep(forAnIgnoredTestStepCalled("Step 6"));
   testOutcome.recordStep(forAFailingTestStepCalled("Step 7", new AssertionError("Oh bother!")));
   testOutcome.recordStep(forAFailingTestStepCalled("Step 8", new AssertionError("Oh bother!")));
   testOutcome.recordStep(forASkippedTestStepCalled("Step 9"));
   testOutcome.recordStep(forAPendingTestStepCalled("Step 10"));
   testOutcome.recordStep(forAPendingTestStepCalled("Step 11"));
   testOutcome.recordStep(forAPendingTestStepCalled("Step 12"));
   testOutcome.endGroup();
   testOutcome.endGroup();
 }
コード例 #12
0
  @Test
  public void should_list_screenshots_for_leaf_steps_in_nested_steps() {
    testOutcome.recordStep(forASuccessfulTestStepCalled("step_1"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("step_2"));
    testOutcome.startGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("step_2.1"));
    testOutcome.startGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("step_2.1.1"));
    testOutcome.startGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("step_2.1.1.1"));
    testOutcome.endGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("step_2.1.2"));
    testOutcome.endGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("step_2.2"));
    testOutcome.endGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("step_3"));

    List<String> screenshots =
        extract(testOutcome.getScreenshots(), on(Screenshot.class).getFilename());
    assertThat(
        screenshots,
        hasItems("step_1.png", "step_2.1.1.1.png", "step_2.1.2.png", "step_2.2.png", "step_3.png"));
  }
コード例 #13
0
  @Test
  public void should_record_deeply_nested_test_steps() {

    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 1"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2"));
    testOutcome.startGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2.1"));
    testOutcome.startGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2.1.1"));
    testOutcome.startGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2.1.1.1"));
    testOutcome.endGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2.1.2"));
    testOutcome.endGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2.2"));
    testOutcome.endGroup();
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 3"));

    assertThat(
        testOutcome.getTestSteps().toString(),
        is(
            "[Step 1, Step 2 [Step 2.1 [Step 2.1.1 [Step 2.1.1.1], Step 2.1.2], Step 2.2], Step 3]"));
  }
コード例 #14
0
  @Test
  public void a_test_group_with_a_failing_test_fails() {

    testOutcome.startGroup("A group");
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 1"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 2"));
    testOutcome.recordStep(forAFailingTestStepCalled("Step 3", new AssertionError("Oh bother!")));
    testOutcome.recordStep(forASkippedTestStepCalled("Step 4"));
    testOutcome.recordStep(forAnIgnoredTestStepCalled("Step 5"));
    testOutcome.recordStep(forASuccessfulTestStepCalled("Step 4"));
    testOutcome.endGroup();

    TestStep aGroup = testOutcome.getTestSteps().get(0);
    assertThat(aGroup.getResult(), is(TestResult.FAILURE));
  }
コード例 #15
0
 /**
  * Creates a new step with this name and immediately turns it into a step group. TODO: Review
  * where this is used, as it is mainly for backward compatibility.
  */
 @Deprecated
 public void startGroup(final String groupName) {
   recordStep(new TestStep(groupName));
   startGroup();
 }