Skip to content

Commit

Permalink
Merge pull request #22 from Xray-App/fix_timestamp_format
Browse files Browse the repository at this point in the history
fixes #21 - changed timestamp format due to windows; fixes also a test
  • Loading branch information
bitcoder authored Sep 14, 2022
2 parents 7858393 + 8110cbd commit aa15dcc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ JUnit 5 provides a [legacy XML reporter for the jupiter engine](https://junit.or

## TO DOs

- cleanup code
- add more tests
...

## FAQ

Expand All @@ -227,7 +226,6 @@ Probably. As there is no official JUnit XML schema, it's hard to say that in adv
3. Why use a custom JUnit XML report instead of Xray JSON report?
For several reasons. One of them is that it was easier to take advantage of the existing code and adapt it.


## Contact

You may find me on [Twitter](https://twitter.com/darktelecom).
Expand All @@ -240,9 +238,8 @@ For Xray specific questions, please contact [Xray's support team](https://jira.g
- [How Xray processes JUnit XML reports](https://docs.getxray.app/display/XRAYCLOUD/Taking+advantage+of+JUnit+XML+reports)
- [JUnit 5 legacy XML reporter](https://junit.org/junit5/docs/current/api/org.junit.platform.reporting/org/junit/platform/reporting/legacy/xml/LegacyXmlReportGeneratingListener.html)


## LICENSE

Based on code from [JUnit5](https://github.com/junit-team/junit5/) project.
Based on code from [JUnit5](https://github.com/junit-team/junit5/) project.

[Eclipse Public License - v 2.0](LICENSE)
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>app.getxray</groupId>
<artifactId>xray-junit-extensions</artifactId>
<packaging>jar</packaging>
<version>0.6.1</version>
<version>0.6.2</version>
<name>xray-junit-extensions</name>
<description>Improvements for JUnit that allow you to take better advantage of JUnit 5 (jupiter engine) whenever using it together with Xray Test Management.</description>
<url>https://github.com/Xray-App/xray-junit-extensions</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private void writeXmlReportSafely(TestIdentifier testIdentifier, String rootName
fileName = "TEST-" + rootName;
}
if (this.addTimestampToReportFilename) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy_MM_dd_HH:mm:ss_SSS");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy_MM_dd-HH_mm_ss_SSS");
fileName += "-" + LocalDateTime.now(this.clock).format(formatter);
}
fileName += ".xml";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import static org.mockito.Mockito.times;

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.URL;
import java.nio.file.FileSystems;
Expand All @@ -37,6 +39,7 @@
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Base64;
import java.util.Properties;

import javax.xml.XMLConstants;
import javax.xml.transform.dom.DOMSource;
Expand Down Expand Up @@ -109,7 +112,7 @@ public void shouldSupportCustomReportNamesWithTimestamp() throws Exception {

executeTestMethodWithCustomProperties(TEST_EXAMPLES_CLASS, testMethodName, customPropertiesFile, "", clock);

String reportName = "custom-report-junit-2021_03_24_12:01:02_456.xml";
String reportName = "custom-report-junit-2021_03_24-12_01_02_456.xml";
Match testsuite = readValidXmlFile(tempDirectory.resolve(reportName));
Match testcase = testsuite.child("testcase");
assertThat(testcase.attr("name", String.class)).isEqualTo(testMethodName);
Expand All @@ -126,9 +129,15 @@ public void shouldSupportCustomReportAbsoluteDirectory() throws Exception {
String testMethodName = "legacyTest";

String customReportDir = tempDirectory.resolve("custom_reports").toString();
String customProperties = "#report_filename=custom-report-junit\nreport_directory=" + customReportDir + "\n# add_timestamp_to_report_filename=true\n";
Path customPropertiesFile = Files.createTempFile("xray-junit-extensions", ".properties");
Files.write(customPropertiesFile, customProperties.getBytes());
//String customProperties = "#report_filename=custom-report-junit\nreport_directory=" + customReportDir + "\n# add_timestamp_to_report_filename=true\n";
//Files.write(customPropertiesFile, customProperties.getBytes());

Properties properties = new Properties();
OutputStream outputStream = new FileOutputStream(customPropertiesFile.toString());
properties.setProperty("report_directory", customReportDir);
properties.store(outputStream, null);

executeTestMethodWithCustomProperties(TEST_EXAMPLES_CLASS, testMethodName, customPropertiesFile, "", Clock.systemDefaultZone());

Match testsuite = readValidXmlFile(tempDirectory.resolve("custom_reports").resolve(REPORT_NAME));
Expand Down

0 comments on commit aa15dcc

Please sign in to comment.