diff --git a/Cargo.toml b/Cargo.toml index 1bcdec60..20b6670b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ thiserror = "1.0.18" termcolor = "1.1.0" textwrap = { version = "0.11", features = ["term_size"] } pathdiff = "0.2.0" +junit-report = "0.3.0" [[test]] name = "cucumber_builder" diff --git a/src/cucumber.rs b/src/cucumber.rs index 047b2c14..0f048199 100644 --- a/src/cucumber.rs +++ b/src/cucumber.rs @@ -22,7 +22,7 @@ impl Default for Cucumber { Cucumber { steps: Default::default(), features: Default::default(), - event_handler: Box::new(crate::output::BasicOutput::default()), + event_handler: Box::new(crate::output::JunitOutput::default()), } } } diff --git a/src/output/junit.rs b/src/output/junit.rs new file mode 100644 index 00000000..4cac2490 --- /dev/null +++ b/src/output/junit.rs @@ -0,0 +1,56 @@ +// Copyright (c) 2018-2020 Brendan Molloy +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +use junit_report::{Duration, Report, TestCase, TestSuite}; + +use crate::event::FeatureEvent; +use crate::{ + event::{CucumberEvent}, + EventHandler, +}; +use std::io::stdout; + +pub struct JunitOutput { + report: Report, + test_suite: TestSuite, +} + +impl Default for JunitOutput { + fn default() -> JunitOutput { + JunitOutput { + report: Report::new(), + test_suite: TestSuite::new("default"), + } + } +} + +impl JunitOutput {} + +impl EventHandler for JunitOutput { + fn handle_event(&mut self, event: CucumberEvent) { + match event { + CucumberEvent::Starting => {} + CucumberEvent::Feature(feature, event) => match event { + FeatureEvent::Starting => self.test_suite = TestSuite::new(feature.name.as_ref()), + FeatureEvent::Scenario(scenario, _event) => { + let test_case = TestCase::success( + scenario.name.as_ref(), + Duration::seconds(5), + Some("you-tell-me".parse().unwrap()), + ); + self.test_suite.add_testcase(test_case); + } + FeatureEvent::Rule(_rule, _event) => {} + FeatureEvent::Finished => { + self.report.add_testsuite(self.test_suite.clone()); + self.report.write_xml(stdout()).unwrap(); + } + }, + CucumberEvent::Finished => {} + } + } +} diff --git a/src/output/mod.rs b/src/output/mod.rs index a3e35b8d..5c7e9d79 100644 --- a/src/output/mod.rs +++ b/src/output/mod.rs @@ -7,5 +7,7 @@ // except according to those terms. mod default; +mod junit; pub use default::BasicOutput; +pub use junit::JunitOutput;