Implement NUnit 3 parser.

This commit is contained in:
Kevin Ring 2023-01-19 12:27:34 +11:00 committed by Jozef Izso
parent b34d4b1bfe
commit 49c1f3ae6c
5 changed files with 372 additions and 0 deletions

View file

@ -0,0 +1,28 @@
![Tests failed](https://img.shields.io/badge/tests-3%20passed%2C%205%20failed%2C%201%20skipped-critical)
## ❌ <a id="user-content-r0" href="#r0">fixtures/dotnet-nunit.xml</a>
**9** tests were completed in **0ms** with **3** passed, **5** failed and **1** skipped.
|Test suite|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|
|[DotnetTests.NUnitV3Tests.dll.DotnetTests.XUnitTests](#r0s0)|3✅|5❌|1⚪|0ms|
### ❌ <a id="user-content-r0s0" href="#r0s0">DotnetTests.NUnitV3Tests.dll.DotnetTests.XUnitTests</a>
```
CalculatorTests
✅ Is_Even_Number(2)
❌ Is_Even_Number(3)
Expected: True
But was: False
❌ Exception_In_TargetTest
System.DivideByZeroException : Attempted to divide by zero.
❌ Exception_In_Test
System.Exception : Test
❌ Failing_Test
Expected: 3
But was: 2
✅ Passing_Test
✅ Passing_Test_With_Description
⚪ Skipped_Test
❌ Timeout_Test
```

View file

@ -0,0 +1,107 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`dotnet-nunit tests report from ./reports/dotnet test results matches snapshot 1`] = `
TestRunResult {
"path": "fixtures/dotnet-nunit.xml",
"suites": Array [
TestSuiteResult {
"groups": Array [
TestGroupResult {
"name": "CalculatorTests",
"tests": Array [
TestCaseResult {
"error": undefined,
"name": "Is_Even_Number(2)",
"result": "success",
"time": 0.000622,
},
TestCaseResult {
"error": Object {
"details": " at DotnetTests.XUnitTests.CalculatorTests.Is_Even_Number(Int32 i) in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporter\\\\reports\\\\dotnet\\\\DotnetTests.NUnitV3Tests\\\\CalculatorTests.cs:line 61
",
"line": undefined,
"message": " Expected: True
But was: False
",
"path": undefined,
},
"name": "Is_Even_Number(3)",
"result": "failed",
"time": 0.001098,
},
TestCaseResult {
"error": Object {
"details": " at DotnetTests.Unit.Calculator.Div(Int32 a, Int32 b) in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporter\\\\reports\\\\dotnet\\\\DotnetTests.Unit\\\\Calculator.cs:line 9
at DotnetTests.XUnitTests.CalculatorTests.Exception_In_TargetTest() in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporter\\\\reports\\\\dotnet\\\\DotnetTests.NUnitV3Tests\\\\CalculatorTests.cs:line 33",
"line": undefined,
"message": "System.DivideByZeroException : Attempted to divide by zero.",
"path": undefined,
},
"name": "Exception_In_TargetTest",
"result": "failed",
"time": 0.022805,
},
TestCaseResult {
"error": Object {
"details": " at DotnetTests.XUnitTests.CalculatorTests.Exception_In_Test() in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporter\\\\reports\\\\dotnet\\\\DotnetTests.NUnitV3Tests\\\\CalculatorTests.cs:line 39",
"line": undefined,
"message": "System.Exception : Test",
"path": undefined,
},
"name": "Exception_In_Test",
"result": "failed",
"time": 0.000528,
},
TestCaseResult {
"error": Object {
"details": " at DotnetTests.XUnitTests.CalculatorTests.Failing_Test() in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporter\\\\reports\\\\dotnet\\\\DotnetTests.NUnitV3Tests\\\\CalculatorTests.cs:line 27
",
"line": undefined,
"message": " Expected: 3
But was: 2
",
"path": undefined,
},
"name": "Failing_Test",
"result": "failed",
"time": 0.028162,
},
TestCaseResult {
"error": undefined,
"name": "Passing_Test",
"result": "success",
"time": 0.000238,
},
TestCaseResult {
"error": undefined,
"name": "Passing_Test_With_Description",
"result": "success",
"time": 0.000135,
},
TestCaseResult {
"error": undefined,
"name": "Skipped_Test",
"result": "skipped",
"time": 0.000398,
},
TestCaseResult {
"error": Object {
"details": "",
"line": undefined,
"message": "",
"path": undefined,
},
"name": "Timeout_Test",
"result": "failed",
"time": 0.014949,
},
],
},
],
"name": "DotnetTests.NUnitV3Tests.dll.DotnetTests.XUnitTests",
"totalTime": undefined,
},
],
"totalTime": 0.230308,
}
`;

View file

@ -0,0 +1,29 @@
import * as fs from 'fs'
import * as path from 'path'
import {DotNetNunitParser} from '../src/parsers/dotnet-nunit/dotnet-nunit-parser'
import {ParseOptions} from '../src/test-parser'
import {getReport} from '../src/report/get-report'
import {normalizeFilePath} from '../src/utils/path-utils'
describe('dotnet-nunit tests', () => {
it('report from ./reports/dotnet test results matches snapshot', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-nunit.xml')
const outputPath = path.join(__dirname, '__outputs__', 'dotnet-nunit.md')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const opts: ParseOptions = {
parseErrors: true,
trackedFiles: ['DotnetTests.Unit/Calculator.cs', 'DotnetTests.NUnitV3Tests/CalculatorTests.cs']
}
const parser = new DotNetNunitParser(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)
})
})