forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxUnitParser.unit.test.ts
More file actions
151 lines (133 loc) · 5.48 KB
/
xUnitParser.unit.test.ts
File metadata and controls
151 lines (133 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// tslint:disable:max-func-body-length
'use strict';
import { expect } from 'chai';
import * as typeMoq from 'typemoq';
import { IFileSystem } from '../../../client/common/platform/types';
import { IXUnitParser, Tests, TestStatus } from '../../../client/testing/common/types';
import { XUnitParser } from '../../../client/testing/common/xUnitParser';
import { createDeclaratively, createEmptyResults, TestItem } from '../results';
suite('Testing - parse JUnit XML file', () => {
let parser: IXUnitParser;
let fs: typeMoq.IMock<IFileSystem>;
setup(() => {
fs = typeMoq.Mock.ofType<IFileSystem>(undefined, typeMoq.MockBehavior.Strict);
parser = new XUnitParser(fs.object);
});
function fixResult(node: TestItem, file: string, line: number) {
switch (node.status) {
case TestStatus.Pass:
node.passed = true;
break;
case TestStatus.Fail:
case TestStatus.Error:
node.passed = false;
break;
default:
node.passed = undefined;
}
node.file = file;
node.line = line;
}
test('legacy - success with single passing test', async () => {
const tests = createDeclaratively(`
./
test_spam.py
<Tests>
test_spam
`);
const expected = createDeclaratively(`
./
test_spam.py
<Tests>
test_spam P 1.001
`);
fixResult(expected.testFunctions[0].testFunction, 'test_spam.py', 3);
const filename = 'x/y/z/results.xml';
fs.setup((f) => f.readFile(filename)).returns(() =>
Promise.resolve(`
<?xml version="1.0" encoding="utf-8"?>
<testsuite errors="0" failures="0" hostname="linux-desktop" name="pytest" skipped="0" tests="1" time="1.011" timestamp="2019-08-29T15:59:08.757654">
<testcase classname="test_spam.Tests" file="test_spam.py" line="3" name="test_spam" time="1.001">
</testcase>
</testsuite>
`)
);
await parser.updateResultsFromXmlLogFile(tests, filename);
expect(tests).to.deep.equal(expected);
fs.verifyAll();
});
test('success with single passing test', async () => {
const tests = createDeclaratively(`
./
test_spam.py
<Tests>
test_spam
`);
const expected = createDeclaratively(`
./
test_spam.py
<Tests>
test_spam P 0.001
`);
fixResult(expected.testFunctions[0].testFunction, 'test_spam.py', 3);
const filename = 'x/y/z/results.xml';
fs.setup((f) => f.readFile(filename)).returns(() =>
Promise.resolve(`
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite errors="0" failures="0" hostname="vm-dev-linux-desktop" name="pytest" skipped="0" tests="1" time="0.011" timestamp="2019-09-05T17:17:35.868863">
<testcase classname="test_spam.Tests" file="test_spam.py" line="3" name="test_spam" time="0.001">
</testcase>
</testsuite>
</testsuites>
`)
);
await parser.updateResultsFromXmlLogFile(tests, filename);
expect(tests).to.deep.equal(expected);
fs.verifyAll();
});
test('no discovered tests', async () => {
const tests: Tests = createEmptyResults();
const expected: Tests = createEmptyResults();
expected.summary.passed = 1; // That's a little strange...
const filename = 'x/y/z/results.xml';
fs.setup((f) => f.readFile(filename)).returns(() =>
Promise.resolve(`
<?xml version="1.0" encoding="utf-8"?>
<testsuite errors="0" failures="0" hostname="linux-desktop" name="pytest" skipped="0" tests="1" time="0.011" timestamp="2019-08-29T15:59:08.757654">
<testcase classname="test_spam.Tests" file="test_spam.py" line="3" name="test_spam" time="0.001">
</testcase>
</testsuite>
`)
);
await parser.updateResultsFromXmlLogFile(tests, filename);
expect(tests).to.deep.equal(expected);
fs.verifyAll();
});
test('no tests run', async () => {
const tests: Tests = createEmptyResults();
const expected: Tests = createEmptyResults();
const filename = 'x/y/z/results.xml';
fs.setup((f) => f.readFile(filename)).returns(() =>
Promise.resolve(`
<?xml version="1.0" encoding="utf-8"?>
<testsuite errors="0" failures="0" hostname="linux-desktop" name="pytest" skipped="0" tests="0" time="0.011" timestamp="2019-08-29T15:59:08.757654">
</testsuite>
`)
);
await parser.updateResultsFromXmlLogFile(tests, filename);
expect(tests).to.deep.equal(expected);
fs.verifyAll();
});
// Missing tests (see https://github.com/microsoft/vscode-python/issues/7447):
// * simple pytest
// * simple nose
// * complex
// * error
// * failure
// * skipped
// * no clobber old if not matching
// * ...
});