forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retain state of tests when auto discovering tests
- Loading branch information
1 parent
e006680
commit 418a1b2
Showing
3 changed files
with
151 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Retain state of tests when auto discovering tests. |
137 changes: 137 additions & 0 deletions
137
src/test/unittests/common/services/storageService.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
'use strict'; | ||
|
||
import * as assert from 'assert'; | ||
import { instance, mock } from 'ts-mockito'; | ||
import { Uri } from 'vscode'; | ||
import { IWorkspaceService } from '../../../../client/common/application/types'; | ||
import { WorkspaceService } from '../../../../client/common/application/workspace'; | ||
import { TestCollectionStorageService } from '../../../../client/unittests/common/services/storageService'; | ||
import { TestResultsService } from '../../../../client/unittests/common/services/testResultsService'; | ||
import { FlattenedTestFunction, FlattenedTestSuite, ITestCollectionStorageService, ITestResultsService, TestFile, TestFolder, TestFunction, Tests, TestStatus, TestSuite, TestType } from '../../../../client/unittests/common/types'; | ||
import { createMockTestDataItem } from '../testUtils.unit.test'; | ||
|
||
// tslint:disable:no-any max-func-body-length | ||
suite('Unit Tests - Storage Service', () => { | ||
let storageService: ITestCollectionStorageService; | ||
let resultsService: ITestResultsService; | ||
let workspaceService: IWorkspaceService; | ||
const workspaceUri = Uri.file(__dirname); | ||
let testData1: Tests; | ||
let testData2: Tests; | ||
setup(() => { | ||
resultsService = mock(TestResultsService); | ||
workspaceService = mock(WorkspaceService); | ||
storageService = new TestCollectionStorageService([], instance(resultsService), instance(workspaceService)); | ||
setupTestData1(); | ||
setupTestData2(); | ||
}); | ||
|
||
function setupTestData1() { | ||
const folder1 = createMockTestDataItem<TestFolder>(TestType.testFolder, '1'); | ||
const file1 = createMockTestDataItem<TestFile>(TestType.testFile, '1'); | ||
folder1.testFiles.push(file1); | ||
const suite1 = createMockTestDataItem<TestSuite>(TestType.testSuite, '1'); | ||
const suite2 = createMockTestDataItem<TestSuite>(TestType.testSuite, '2'); | ||
const fn1 = createMockTestDataItem<TestFunction>(TestType.testFunction, '1'); | ||
const fn2 = createMockTestDataItem<TestFunction>(TestType.testFunction, '2'); | ||
const fn3 = createMockTestDataItem<TestFunction>(TestType.testFunction, '3'); | ||
file1.suites.push(suite1); | ||
file1.suites.push(suite2); | ||
file1.functions.push(fn1); | ||
suite1.functions.push(fn2); | ||
suite2.functions.push(fn3); | ||
const flattendSuite1: FlattenedTestSuite = { | ||
testSuite: suite1, | ||
xmlClassName: suite1.xmlName | ||
} as any; | ||
const flattendSuite2: FlattenedTestSuite = { | ||
testSuite: suite2, | ||
xmlClassName: suite2.xmlName | ||
} as any; | ||
const flattendFn1: FlattenedTestFunction = { | ||
testFunction: fn1, | ||
xmlClassName: fn1.name | ||
} as any; | ||
const flattendFn2: FlattenedTestFunction = { | ||
testFunction: fn2, | ||
xmlClassName: fn2.name | ||
} as any; | ||
const flattendFn3: FlattenedTestFunction = { | ||
testFunction: fn3, | ||
xmlClassName: fn3.name | ||
} as any; | ||
testData1 = { | ||
rootTestFolders: [folder1], | ||
summary: { errors: 0, skipped: 0, passed: 0, failures: 0 }, | ||
testFiles: [file1], | ||
testFolders: [folder1], | ||
testFunctions: [flattendFn1, flattendFn2, flattendFn3], | ||
testSuites: [flattendSuite1, flattendSuite2] | ||
}; | ||
} | ||
|
||
function setupTestData2() { | ||
const folder1 = createMockTestDataItem<TestFolder>(TestType.testFolder, '1'); | ||
const file1 = createMockTestDataItem<TestFile>(TestType.testFile, '1'); | ||
folder1.testFiles.push(file1); | ||
const suite1 = createMockTestDataItem<TestSuite>(TestType.testSuite, '1'); | ||
const suite2 = createMockTestDataItem<TestSuite>(TestType.testSuite, '2'); | ||
const fn1 = createMockTestDataItem<TestFunction>(TestType.testFunction, '1'); | ||
const fn2 = createMockTestDataItem<TestFunction>(TestType.testFunction, '2'); | ||
const fn3 = createMockTestDataItem<TestFunction>(TestType.testFunction, '3'); | ||
file1.suites.push(suite1); | ||
file1.suites.push(suite2); | ||
suite1.functions.push(fn1); | ||
suite1.functions.push(fn2); | ||
suite2.functions.push(fn3); | ||
const flattendSuite1: FlattenedTestSuite = { | ||
testSuite: suite1, | ||
xmlClassName: suite1.xmlName | ||
} as any; | ||
const flattendSuite2: FlattenedTestSuite = { | ||
testSuite: suite2, | ||
xmlClassName: suite2.xmlName | ||
} as any; | ||
const flattendFn1: FlattenedTestFunction = { | ||
testFunction: fn1, | ||
xmlClassName: fn1.name | ||
} as any; | ||
const flattendFn2: FlattenedTestFunction = { | ||
testFunction: fn2, | ||
xmlClassName: fn2.name | ||
} as any; | ||
const flattendFn3: FlattenedTestFunction = { | ||
testFunction: fn3, | ||
xmlClassName: fn3.name | ||
} as any; | ||
testData2 = { | ||
rootTestFolders: [folder1], | ||
summary: { errors: 0, skipped: 0, passed: 0, failures: 0 }, | ||
testFiles: [file1], | ||
testFolders: [folder1], | ||
testFunctions: [flattendFn1, flattendFn2, flattendFn3], | ||
testSuites: [flattendSuite1, flattendSuite2] | ||
}; | ||
} | ||
|
||
test('Merge Status from existing tests', () => { | ||
testData1.testFunctions[0].testFunction.passed = true; | ||
testData1.testFunctions[1].testFunction.status = TestStatus.Fail; | ||
testData1.testFunctions[2].testFunction.time = 1234; | ||
|
||
assert.notDeepEqual(testData1.testFunctions[0].testFunction, testData2.testFunctions[0].testFunction); | ||
assert.notDeepEqual(testData1.testFunctions[1].testFunction, testData2.testFunctions[1].testFunction); | ||
assert.notDeepEqual(testData1.testFunctions[2].testFunction, testData2.testFunctions[2].testFunction); | ||
|
||
storageService.storeTests(workspaceUri, testData1); | ||
storageService.storeTests(workspaceUri, testData2); | ||
|
||
// Function 1 is in a different suite now, hence should not get updated. | ||
assert.notDeepEqual(testData1.testFunctions[0].testFunction, testData2.testFunctions[0].testFunction); | ||
assert.deepEqual(testData1.testFunctions[1].testFunction, testData2.testFunctions[1].testFunction); | ||
assert.deepEqual(testData1.testFunctions[2].testFunction, testData2.testFunctions[2].testFunction); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters