Skip to content

Commit

Permalink
POC pass at junit output
Browse files Browse the repository at this point in the history
  • Loading branch information
AidaPaul committed May 27, 2020
1 parent d001cbe commit 7018734
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/cucumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<W: World> Default for Cucumber<W> {
Cucumber {
steps: Default::default(),
features: Default::default(),
event_handler: Box::new(crate::output::BasicOutput::default()),
event_handler: Box::new(crate::output::JunitOutput::default()),
}
}
}
Expand Down
56 changes: 56 additions & 0 deletions src/output/junit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2018-2020 Brendan Molloy <[email protected]>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 => {}
}
}
}
2 changes: 2 additions & 0 deletions src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
// except according to those terms.

mod default;
mod junit;

pub use default::BasicOutput;
pub use junit::JunitOutput;

0 comments on commit 7018734

Please sign in to comment.