Skip to content

Commit

Permalink
Add test attributes to junit XML
Browse files Browse the repository at this point in the history
  • Loading branch information
joesantos418 authored and hurl-bot committed Apr 22, 2023
1 parent ba35562 commit f29899c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion integration/tests_ok/junit.out.pattern
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0" encoding="UTF-8"?><testsuites><testsuite><testcase id="tests_ok/test.1.hurl" name="tests_ok/test.1.hurl" time="~~~" /><testcase id="tests_ok/test.2.hurl" name="tests_ok/test.2.hurl" time="~~~" /></testsuite><testsuite><testcase id="tests_ok/test.3.hurl" name="tests_ok/test.3.hurl" time="~~~" /></testsuite></testsuites>
<?xml version="1.0" encoding="UTF-8"?><testsuites><testsuite tests="2" errors="0" failures="0"><testcase id="tests_ok/test.1.hurl" name="tests_ok/test.1.hurl" time="~~~" /><testcase id="tests_ok/test.2.hurl" name="tests_ok/test.2.hurl" time="~~~" /></testsuite><testsuite tests="1" errors="0" failures="0"><testcase id="tests_ok/test.3.hurl" name="tests_ok/test.3.hurl" time="~~~" /></testsuite></testsuites>
17 changes: 16 additions & 1 deletion packages/hurl/src/report/junit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ pub fn write_report(filename: &str, testcases: &[Testcase]) -> Result<(), Error>
}

fn create_testsuite(testcases: &[Testcase]) -> XMLNode {
let mut attrs = indexmap::map::IndexMap::new();
let mut tests = 0;
let mut errors = 0;
let mut failures = 0;

for cases in testcases.iter() {
tests += 1;
errors += cases.get_error_count();
failures += cases.get_fail_count();
}

attrs.insert("tests".to_string(), tests.to_string());
attrs.insert("errors".to_string(), errors.to_string());
attrs.insert("failures".to_string(), failures.to_string());

let children = testcases
.iter()
.map(|t| XMLNode::Element(t.to_xml()))
Expand All @@ -121,7 +136,7 @@ fn create_testsuite(testcases: &[Testcase]) -> XMLNode {
prefix: None,
namespace: None,
namespaces: None,
attributes: indexmap::map::IndexMap::new(),
attributes: attrs,
children,
};
XMLNode::Element(element)
Expand Down
8 changes: 8 additions & 0 deletions packages/hurl/src/report/junit/testcase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ impl Testcase {
children,
}
}

pub fn get_error_count(&self) -> usize {
self.errors.len()
}

pub fn get_fail_count(&self) -> usize {
self.failures.len()
}
}

#[cfg(test)]
Expand Down

0 comments on commit f29899c

Please sign in to comment.