Skip to content

Commit

Permalink
Add tests for TestTreeViewProvider.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed Mar 13, 2019
1 parent 3bcb744 commit 9eac943
Showing 1 changed file with 258 additions and 2 deletions.
260 changes: 258 additions & 2 deletions src/test/unittests/explorer/testTreeViewProvider.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ import { WorkspaceService } from '../../../client/common/application/workspace';
import { IDisposable } from '../../../client/common/types';
import { TestCollectionStorageService } from '../../../client/unittests/common/services/storageService';
import { getTestType } from '../../../client/unittests/common/testUtils';
import { ITestCollectionStorageService, TestStatus, TestType } from '../../../client/unittests/common/types';
import {
ITestCollectionStorageService, TestStatus, TestType
} from '../../../client/unittests/common/types';
import { TestTreeItem } from '../../../client/unittests/explorer/testTreeViewItem';
import { TestTreeViewProvider } from '../../../client/unittests/explorer/testTreeViewProvider';
import { TestDataItem } from '../../../client/unittests/types';
import { noop } from '../../core';
import { createMockTestExplorer as createMockTestTreeProvider, createMockTestsData, getMockTestFile, getMockTestFunction, getMockTestSuite } from './explorerTestData';
import {
createMockTestExplorer as createMockTestTreeProvider, createMockTestsData,
getMockTestFile, getMockTestFolder, getMockTestFunction, getMockTestSuite
} from './explorerTestData';

// tslint:disable:no-any

Expand Down Expand Up @@ -335,4 +340,255 @@ suite('Unit Tests Test Explorer TestTreeViewProvider', () => {
expect(child.name).oneOf(['test_suite', 'test_outer_fn']);
});
});

test('Tree items for subtests are correct', async () => {
const resource = Uri.file(__filename);
// Set up the folder & file.
const folder = getMockTestFolder('tests');
const file = getMockTestFile(`${folder.name}/test_file.py`);
folder.testFiles.push(file);
// Set up the file-level tests.
const func1 = getMockTestFunction(`${file.name}::test_spam`);
file.functions.push(func1);
const func2 = getMockTestFunction(`${file.name}::test_ham[1-2]`);
func2.subtestParent = {
name: 'test_ham',
nameToRun: `${file.name}::test_ham`,
asSuite: {
resource: resource,
name: 'test_ham',
nameToRun: `${file.name}::test_ham`,
functions: [func2],
suites: [],
isUnitTest: false,
isInstance: false,
xmlName: 'test_ham',
time: 0
},
time: 0
};
file.functions.push(func2);
const func3 = getMockTestFunction(`${file.name}::test_ham[3-4]`);
func3.subtestParent = func2.subtestParent;
func3.subtestParent.asSuite.functions.push(func3);
file.functions.push(func3);
// Set up the suite.
const suite = getMockTestSuite(`${file.name}::MyTests`);
file.suites.push(suite);
const func4 = getMockTestFunction('MyTests::test_foo');
suite.functions.push(func4);
const func5 = getMockTestFunction('MyTests::test_bar[2-3]');
func5.subtestParent = {
name: 'test_bar',
nameToRun: `${file.name}::MyTests::test_bar`,
asSuite: {
resource: resource,
name: 'test_bar',
nameToRun: `${file.name}::MyTests::test_bar`,
functions: [func5],
suites: [],
isUnitTest: false,
isInstance: false,
xmlName: 'test_bar',
time: 0
},
time: 0
};
suite.functions.push(func5);
// Set up the tests data.
const testData = createMockTestsData([file]);

const testExplorer = createMockTestTreeProvider(undefined, testData);
const items = [
await testExplorer.getTreeItem(func1),
await testExplorer.getTreeItem(func2),
await testExplorer.getTreeItem(func3),
await testExplorer.getTreeItem(func4),
await testExplorer.getTreeItem(func5),
await testExplorer.getTreeItem(file),
await testExplorer.getTreeItem(suite),
await testExplorer.getTreeItem(func2.subtestParent.asSuite),
await testExplorer.getTreeItem(func5.subtestParent.asSuite)
];

expect(items).to.deep.equal([
new TestTreeItem(func1.resource, func1),
new TestTreeItem(func2.resource, func2),
new TestTreeItem(func3.resource, func3),
new TestTreeItem(func4.resource, func4),
new TestTreeItem(func5.resource, func5),
new TestTreeItem(file.resource, file),
new TestTreeItem(suite.resource, suite),
new TestTreeItem(resource, func2.subtestParent.asSuite),
new TestTreeItem(resource, func5.subtestParent.asSuite)
]);
});

test('Parents for subtests are correct', async () => {
const resource = Uri.file(__filename);
// Set up the folder & file.
const folder = getMockTestFolder('tests');
const file = getMockTestFile(`${folder.name}/test_file.py`);
folder.testFiles.push(file);
// Set up the file-level tests.
const func1 = getMockTestFunction(`${file.name}::test_spam`);
file.functions.push(func1);
const func2 = getMockTestFunction(`${file.name}::test_ham[1-2]`);
func2.subtestParent = {
name: 'test_ham',
nameToRun: `${file.name}::test_ham`,
asSuite: {
resource: resource,
name: 'test_ham',
nameToRun: `${file.name}::test_ham`,
functions: [func2],
suites: [],
isUnitTest: false,
isInstance: false,
xmlName: 'test_ham',
time: 0
},
time: 0
};
file.functions.push(func2);
const func3 = getMockTestFunction(`${file.name}::test_ham[3-4]`);
func3.subtestParent = func2.subtestParent;
func3.subtestParent.asSuite.functions.push(func3);
file.functions.push(func3);
// Set up the suite.
const suite = getMockTestSuite(`${file.name}::MyTests`);
file.suites.push(suite);
const func4 = getMockTestFunction('MyTests::test_foo');
suite.functions.push(func4);
const func5 = getMockTestFunction('MyTests::test_bar[2-3]');
func5.subtestParent = {
name: 'test_bar',
nameToRun: `${file.name}::MyTests::test_bar`,
asSuite: {
resource: resource,
name: 'test_bar',
nameToRun: `${file.name}::MyTests::test_bar`,
functions: [func5],
suites: [],
isUnitTest: false,
isInstance: false,
xmlName: 'test_bar',
time: 0
},
time: 0
};
suite.functions.push(func5);
// Set up the tests data.
const testData = createMockTestsData([file]);

const testExplorer = createMockTestTreeProvider(undefined, testData);
const parents = [
await testExplorer.getParent(func1),
await testExplorer.getParent(func2),
await testExplorer.getParent(func3),
await testExplorer.getParent(func4),
await testExplorer.getParent(func5),
await testExplorer.getParent(suite),
await testExplorer.getParent(func2.subtestParent.asSuite),
await testExplorer.getParent(func3.subtestParent.asSuite),
await testExplorer.getParent(func5.subtestParent.asSuite)
];

expect(parents).to.deep.equal([
file,
func2.subtestParent.asSuite,
func3.subtestParent.asSuite,
suite,
func5.subtestParent.asSuite,
file,
file,
file,
suite
]);
});

test('Children for subtests are correct', async () => {
const resource = Uri.file(__filename);
// Set up the folder & file.
const folder = getMockTestFolder('tests');
const file = getMockTestFile(`${folder.name}/test_file.py`);
folder.testFiles.push(file);
// Set up the file-level tests.
const func1 = getMockTestFunction(`${file.name}::test_spam`);
file.functions.push(func1);
const func2 = getMockTestFunction(`${file.name}::test_ham[1-2]`);
func2.subtestParent = {
name: 'test_ham',
nameToRun: `${file.name}::test_ham`,
asSuite: {
resource: resource,
name: 'test_ham',
nameToRun: `${file.name}::test_ham`,
functions: [func2],
suites: [],
isUnitTest: false,
isInstance: false,
xmlName: 'test_ham',
time: 0
},
time: 0
};
file.functions.push(func2);
const func3 = getMockTestFunction(`${file.name}::test_ham[3-4]`);
func3.subtestParent = func2.subtestParent;
func3.subtestParent.asSuite.functions.push(func3);
file.functions.push(func3);
// Set up the suite.
const suite = getMockTestSuite(`${file.name}::MyTests`);
file.suites.push(suite);
const func4 = getMockTestFunction('MyTests::test_foo');
suite.functions.push(func4);
const func5 = getMockTestFunction('MyTests::test_bar[2-3]');
func5.subtestParent = {
name: 'test_bar',
nameToRun: `${file.name}::MyTests::test_bar`,
asSuite: {
resource: resource,
name: 'test_bar',
nameToRun: `${file.name}::MyTests::test_bar`,
functions: [func5],
suites: [],
isUnitTest: false,
isInstance: false,
xmlName: 'test_bar',
time: 0
},
time: 0
};
suite.functions.push(func5);
// Set up the tests data.
const testData = createMockTestsData([file]);

const testExplorer = createMockTestTreeProvider(undefined, testData);
const childrens = [
await testExplorer.getChildren(func1),
await testExplorer.getChildren(func2),
await testExplorer.getChildren(func3),
await testExplorer.getChildren(func4),
await testExplorer.getChildren(func5),
await testExplorer.getChildren(file),
await testExplorer.getChildren(suite),
await testExplorer.getChildren(func2.subtestParent.asSuite),
await testExplorer.getChildren(func3.subtestParent.asSuite),
await testExplorer.getChildren(func5.subtestParent.asSuite)
];

expect(childrens).to.deep.equal([
[],
[],
[],
[],
[],
[func1, suite, func2.subtestParent.asSuite],
[func4, func5.subtestParent.asSuite],
[func2, func3],
[func2, func3],
[func5]
]);
});
});

0 comments on commit 9eac943

Please sign in to comment.