#include namespace bd = bandit::detail; go_bandit([](){ describe("xunit_reporter:", [&](){ std::unique_ptr stm; bd::default_failure_formatter formatter; std::unique_ptr reporter; auto output = [&](){ return stm->str(); }; before_each([&](){ stm = std::unique_ptr(new std::stringstream()); reporter = std::unique_ptr(new bd::xunit_reporter(*stm, formatter)); }); describe("an empty test run", [&](){ before_each([&](){ reporter->test_run_starting(); reporter->test_run_complete(); }); it("adds a header to the output", [&](){ AssertThat(output(), StartsWith("\n")); }); it("outputs an empty test report", [&](){ AssertThat(output(), Contains( "\n" "\n")); }); }); describe("a test run with one, successful, test", [&](){ before_each([&](){ reporter->test_run_starting(); reporter->context_starting("my context"); reporter->it_starting("my test"); reporter->it_succeeded("my test"); reporter->context_ended("my context"); reporter->test_run_complete(); }); it("outputs info about the successful test", [&](){ AssertThat(output(), Contains( "\n" "\t\n" "\t\n" "\n")); }); }); describe("a test run with one, failing test", [&](){ before_each([&](){ reporter->test_run_starting(); reporter->context_starting("my context"); reporter->it_starting("my test"); bd::assertion_exception exception("assertion failed!", "some_file", 123); reporter->it_failed("my test", exception); reporter->context_ended("my context"); reporter->test_run_complete(); }); it("outputs the failing test", [&](){ AssertThat(output(), Contains( "\n" "\t\n" "\t\t\n" "\t\n" "\n")); }); }); describe("a test run with one test with an unknown error", [&](){ before_each([&](){ reporter->test_run_starting(); reporter->context_starting("my context"); reporter->it_starting("my test"); reporter->it_unknown_error("my test"); reporter->context_ended("my context"); reporter->test_run_complete(); }); it("outputs the erroneous test", [&](){ AssertThat(output(), Contains( "\n" "\t\n" "\t\t\n" "\t\n" "\n")); }); }); describe("a test run with one test failing with characters that need escaping", [&](){ before_each([&](){ reporter->test_run_starting(); reporter->context_starting("my context & < > \\ \""); reporter->it_starting("my test & < > \\ \""); bd::assertion_exception exception("assertion failed & < > \\ \"", "some_file", 123); reporter->it_failed("my test & < > \\ \"", exception); reporter->context_ended("my context & < > \\ \""); reporter->test_run_complete(); }); it("outputs the escaped characters", [&](){ AssertThat(output(), Contains( "\n" "\t\n" "\t\t\n" "\t\n" "\n")); }); }); describe("a context with a skipped test", [&](){ before_each([&](){ reporter->test_run_starting(); reporter->context_starting("my context"); reporter->it_starting("my test"); reporter->it_succeeded("my test"); reporter->it_skip("my skipped test"); reporter->context_ended("my context"); reporter->test_run_complete(); }); it("outputs info about the skipped test", [&](){ AssertThat(output(), Contains( "\n" "\t\n" "\t\n" "\t\n" "\t\t\n" "\t\n" "\n")); }); }); }); });