From f24c625f568f0813958d2f89d30ab4a4bc802ef4 Mon Sep 17 00:00:00 2001 From: Jozef Izso Date: Fri, 26 Dec 2025 15:56:54 +0100 Subject: [PATCH] Create tests for sample JUnit files Source: https://github.com/testmoapp/junitxml/ --- __tests__/__outputs__/junit-basic.md | 23 +++ __tests__/__outputs__/junit-complete.md | 22 +++ .../__snapshots__/java-junit.test.ts.snap | 150 ++++++++++++++++++ .../fixtures/external/java/junit4-basic.xml | 31 ++++ .../external/java/junit4-complete.xml | 141 ++++++++++++++++ __tests__/java-junit.test.ts | 40 +++++ 6 files changed, 407 insertions(+) create mode 100644 __tests__/__outputs__/junit-basic.md create mode 100644 __tests__/__outputs__/junit-complete.md create mode 100644 __tests__/fixtures/external/java/junit4-basic.xml create mode 100644 __tests__/fixtures/external/java/junit4-complete.xml diff --git a/__tests__/__outputs__/junit-basic.md b/__tests__/__outputs__/junit-basic.md new file mode 100644 index 0000000..642aaf4 --- /dev/null +++ b/__tests__/__outputs__/junit-basic.md @@ -0,0 +1,23 @@ +![Tests failed](https://img.shields.io/badge/tests-5%20passed%2C%201%20failed-critical) +|Report|Passed|Failed|Skipped|Time| +|:---|---:|---:|---:|---:| +|[fixtures/external/java/junit4-basic.xml](#user-content-r0)|5 ✅|1 ❌||16s| +## ❌ fixtures/external/java/junit4-basic.xml +**6** tests were completed in **16s** with **5** passed, **1** failed and **0** skipped. +|Test suite|Passed|Failed|Skipped|Time| +|:---|---:|---:|---:|---:| +|[Tests.Authentication](#user-content-r0s0)|2 ✅|1 ❌||9s| +|[Tests.Registration](#user-content-r0s1)|3 ✅|||7s| +### ❌ Tests.Authentication +``` +✅ testCase7 +✅ testCase8 +❌ testCase9 + AssertionError: Assertion error message +``` +### ✅ Tests.Registration +``` +✅ testCase1 +✅ testCase2 +✅ testCase3 +``` \ No newline at end of file diff --git a/__tests__/__outputs__/junit-complete.md b/__tests__/__outputs__/junit-complete.md new file mode 100644 index 0000000..8dbbb7c --- /dev/null +++ b/__tests__/__outputs__/junit-complete.md @@ -0,0 +1,22 @@ +![Tests failed](https://img.shields.io/badge/tests-5%20passed%2C%202%20failed%2C%201%20skipped-critical) +|Report|Passed|Failed|Skipped|Time| +|:---|---:|---:|---:|---:| +|[fixtures/external/java/junit4-complete.xml](#user-content-r0)|5 ✅|2 ❌|1 ⚪|16s| +## ❌ fixtures/external/java/junit4-complete.xml +**8** tests were completed in **16s** with **5** passed, **2** failed and **1** skipped. +|Test suite|Passed|Failed|Skipped|Time| +|:---|---:|---:|---:|---:| +|[Tests.Registration](#user-content-r0s0)|5 ✅|2 ❌|1 ⚪|16s| +### ❌ Tests.Registration +``` +✅ testCase1 +✅ testCase2 +✅ testCase3 +⚪ testCase4 +❌ testCase5 + AssertionError: Expected value did not match. +❌ testCase6 + ArithmeticError: Division by zero. +✅ testCase7 +✅ testCase8 +``` \ No newline at end of file diff --git a/__tests__/__snapshots__/java-junit.test.ts.snap b/__tests__/__snapshots__/java-junit.test.ts.snap index 38daca9..ce56a55 100644 --- a/__tests__/__snapshots__/java-junit.test.ts.snap +++ b/__tests__/__snapshots__/java-junit.test.ts.snap @@ -6878,3 +6878,153 @@ at java.lang.Thread.run(Thread.java:748) "totalTime": 2126531.0000000005, } `; + +exports[`java-junit tests report from testmo/junitxml basic example matches snapshot 1`] = ` +TestRunResult { + "path": "fixtures/external/java/junit4-basic.xml", + "suites": [ + TestSuiteResult { + "groups": [ + TestGroupResult { + "name": "", + "tests": [ + TestCaseResult { + "error": undefined, + "name": "testCase1", + "result": "success", + "time": 2113.871, + }, + TestCaseResult { + "error": undefined, + "name": "testCase2", + "result": "success", + "time": 1051, + }, + TestCaseResult { + "error": undefined, + "name": "testCase3", + "result": "success", + "time": 3441, + }, + ], + }, + ], + "name": "Tests.Registration", + "totalTime": 6605.870999999999, + }, + TestSuiteResult { + "groups": [ + TestGroupResult { + "name": "", + "tests": [ + TestCaseResult { + "error": undefined, + "name": "testCase7", + "result": "success", + "time": 2508, + }, + TestCaseResult { + "error": undefined, + "name": "testCase8", + "result": "success", + "time": 1230.8159999999998, + }, + TestCaseResult { + "error": { + "details": undefined, + "line": undefined, + "message": "AssertionError: Assertion error message", + "path": undefined, + }, + "name": "testCase9", + "result": "failed", + "time": 982, + }, + ], + }, + ], + "name": "Tests.Authentication", + "totalTime": 9076.816, + }, + ], + "totalTime": 15682.687, +} +`; + +exports[`java-junit tests report from testmo/junitxml complete example matches snapshot 1`] = ` +TestRunResult { + "path": "fixtures/external/java/junit4-complete.xml", + "suites": [ + TestSuiteResult { + "groups": [ + TestGroupResult { + "name": "", + "tests": [ + TestCaseResult { + "error": undefined, + "name": "testCase1", + "result": "success", + "time": 2436, + }, + TestCaseResult { + "error": undefined, + "name": "testCase2", + "result": "success", + "time": 1534, + }, + TestCaseResult { + "error": undefined, + "name": "testCase3", + "result": "success", + "time": 822, + }, + TestCaseResult { + "error": undefined, + "name": "testCase4", + "result": "skipped", + "time": 0, + }, + TestCaseResult { + "error": { + "details": undefined, + "line": undefined, + "message": "AssertionError: Expected value did not match.", + "path": undefined, + }, + "name": "testCase5", + "result": "failed", + "time": 2902.412, + }, + TestCaseResult { + "error": { + "details": undefined, + "line": undefined, + "message": "ArithmeticError: Division by zero.", + "path": undefined, + }, + "name": "testCase6", + "result": "failed", + "time": 3819, + }, + TestCaseResult { + "error": undefined, + "name": "testCase7", + "result": "success", + "time": 2944, + }, + TestCaseResult { + "error": undefined, + "name": "testCase8", + "result": "success", + "time": 1625.275, + }, + ], + }, + ], + "name": "Tests.Registration", + "totalTime": 16082.687, + }, + ], + "totalTime": 16082.687, +} +`; diff --git a/__tests__/fixtures/external/java/junit4-basic.xml b/__tests__/fixtures/external/java/junit4-basic.xml new file mode 100644 index 0000000..cece7ae --- /dev/null +++ b/__tests__/fixtures/external/java/junit4-basic.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/__tests__/fixtures/external/java/junit4-complete.xml b/__tests__/fixtures/external/java/junit4-complete.xml new file mode 100644 index 0000000..14f131b --- /dev/null +++ b/__tests__/fixtures/external/java/junit4-complete.xml @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + Config line #1 + Config line #2 + Config line #3 + + + + + Data written to standard out. + + + Data written to standard error. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Data written to standard out. + + + Data written to standard error. + + + + + + + + + + + + + This text describes the purpose of this test case and provides + an overview of what the test does and how it works. + + + + + diff --git a/__tests__/java-junit.test.ts b/__tests__/java-junit.test.ts index 83a7dec..8f8c7ae 100644 --- a/__tests__/java-junit.test.ts +++ b/__tests__/java-junit.test.ts @@ -73,6 +73,46 @@ describe('java-junit tests', () => { fs.writeFileSync(outputPath, report) }) + it('report from testmo/junitxml basic example matches snapshot', async () => { + const fixturePath = path.join(__dirname, 'fixtures', 'external', 'java', 'junit4-basic.xml') + const outputPath = path.join(__dirname, '__outputs__', 'junit-basic.md') + const filePath = normalizeFilePath(path.relative(__dirname, fixturePath)) + const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'}) + + const opts: ParseOptions = { + parseErrors: true, + trackedFiles: [] + } + + const parser = new JavaJunitParser(opts) + const result = await parser.parse(filePath, fileContent) + expect(result).toMatchSnapshot() + + const report = getReport([result]) + fs.mkdirSync(path.dirname(outputPath), {recursive: true}) + fs.writeFileSync(outputPath, report) + }) + + it('report from testmo/junitxml complete example matches snapshot', async () => { + const fixturePath = path.join(__dirname, 'fixtures', 'external', 'java', 'junit4-complete.xml') + const outputPath = path.join(__dirname, '__outputs__', 'junit-complete.md') + const filePath = normalizeFilePath(path.relative(__dirname, fixturePath)) + const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'}) + + const opts: ParseOptions = { + parseErrors: true, + trackedFiles: [] + } + + const parser = new JavaJunitParser(opts) + const result = await parser.parse(filePath, fileContent) + expect(result).toMatchSnapshot() + + const report = getReport([result]) + fs.mkdirSync(path.dirname(outputPath), {recursive: true}) + fs.writeFileSync(outputPath, report) + }) + it('parses empty failures in test results', async () => { const fixturePath = path.join(__dirname, 'fixtures', 'external', 'java', 'empty_failures.xml') const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))