Skip to content

Commit 5d3a063

Browse files
committed
Add integration test for .runsettings in unit tests
1 parent f0f0e4a commit 5d3a063

File tree

4 files changed

+65
-9
lines changed

4 files changed

+65
-9
lines changed

omnisharptest/omnisharpIntegrationTests/codeLensProvider.integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ suite(`CodeLensProvider options: ${testAssetWorkspace.description}`, function ()
117117
await csharpConfig.update('codeLens.enableTestsCodeLens', false);
118118

119119
const codeLenses = await GetCodeLenses(fileUri, 100);
120-
expect(codeLenses.length).to.equal(2);
120+
expect(codeLenses.length).to.equal(3);
121121

122122
for (const codeLens of codeLenses) {
123123
expect(codeLens.isResolved).to.be.true;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<RunSettings>
2+
<RunConfiguration>
3+
<TestCaseFilter>TestCategory=include</TestCaseFilter>
4+
</RunConfiguration>
5+
</RunSettings>

test/integrationTests/testAssets/slnWithCsproj/test/UnitTest1.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,12 @@ public void Test1()
1010
{
1111

1212
}
13+
14+
[Fact]
15+
[Trait("TestCategory", "include")]
16+
public void Test2()
17+
{
18+
19+
}
1320
}
1421
}

test/integrationTests/unitTests.integration.test.ts

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ jestLib.describe(`Unit Testing ${testAssetWorkspace.description}`, function () {
1616
});
1717

1818
jestLib.beforeEach(async function () {
19+
vscode.workspace
20+
.getConfiguration()
21+
.update('dotnet.unitTests.runSettingsPath', undefined, vscode.ConfigurationTarget.Workspace);
1922
const fileName = path.join('test', 'UnitTest1.cs');
2023
await openFileInWorkspaceAsync(fileName);
2124
});
@@ -26,9 +29,10 @@ jestLib.describe(`Unit Testing ${testAssetWorkspace.description}`, function () {
2629

2730
jestLib.test('Unit test code lens items are displayed', async () => {
2831
const codeLenses = await getCodeLensesAsync();
29-
jestLib.expect(codeLenses).toHaveLength(6);
32+
jestLib.expect(codeLenses).toHaveLength(9);
3033

3134
const classRange = new vscode.Range(new vscode.Position(5, 17), new vscode.Position(5, 26));
35+
3236
// Class level debug all tests
3337
jestLib.expect(codeLenses[1].command?.command).toBe('dotnet.test.run');
3438
jestLib.expect(codeLenses[1].command?.title).toBe('Debug All Tests');
@@ -41,23 +45,31 @@ jestLib.describe(`Unit Testing ${testAssetWorkspace.description}`, function () {
4145
jestLib.expect(codeLenses[2].command?.arguments![0].attachDebugger).toBe(false);
4246
jestLib.expect(codeLenses[2].range).toStrictEqual(classRange);
4347

44-
const methodRange = new vscode.Range(new vscode.Position(8, 20), new vscode.Position(8, 25));
45-
// Method level debug test
48+
let methodRange = new vscode.Range(new vscode.Position(8, 20), new vscode.Position(8, 25));
49+
// Method level run and debug test
4650
jestLib.expect(codeLenses[4].command?.command).toBe('dotnet.test.run');
4751
jestLib.expect(codeLenses[4].command?.title).toBe('Debug Test');
4852
jestLib.expect(codeLenses[4].command?.arguments![0].attachDebugger).toBe(true);
4953
jestLib.expect(codeLenses[4].range).toStrictEqual(methodRange);
50-
51-
// Method level run test
5254
jestLib.expect(codeLenses[5].command?.command).toBe('dotnet.test.run');
5355
jestLib.expect(codeLenses[5].command?.title).toBe('Run Test');
5456
jestLib.expect(codeLenses[5].command?.arguments![0].attachDebugger).toBe(false);
5557
jestLib.expect(codeLenses[5].range).toStrictEqual(methodRange);
58+
59+
methodRange = new vscode.Range(new vscode.Position(15, 20), new vscode.Position(15, 25));
60+
jestLib.expect(codeLenses[7].command?.command).toBe('dotnet.test.run');
61+
jestLib.expect(codeLenses[7].command?.title).toBe('Debug Test');
62+
jestLib.expect(codeLenses[7].command?.arguments![0].attachDebugger).toBe(true);
63+
jestLib.expect(codeLenses[7].range).toStrictEqual(methodRange);
64+
jestLib.expect(codeLenses[8].command?.command).toBe('dotnet.test.run');
65+
jestLib.expect(codeLenses[8].command?.title).toBe('Run Test');
66+
jestLib.expect(codeLenses[8].command?.arguments![0].attachDebugger).toBe(false);
67+
jestLib.expect(codeLenses[8].range).toStrictEqual(methodRange);
5668
});
5769

5870
jestLib.test('Code lens command executes tests', async () => {
5971
const codeLenses = await getCodeLensesAsync();
60-
jestLib.expect(codeLenses).toHaveLength(6);
72+
jestLib.expect(codeLenses).toHaveLength(9);
6173

6274
const runAllTestsCommand = codeLenses[2].command!;
6375
jestLib.expect(runAllTestsCommand.title).toBe('Run All Tests');
@@ -67,8 +79,8 @@ jestLib.describe(`Unit Testing ${testAssetWorkspace.description}`, function () {
6779
runAllTestsCommand.arguments![0]
6880
);
6981
jestLib.expect(testResults).toBeDefined();
70-
jestLib.expect(testResults?.totalTests).toEqual(1);
71-
jestLib.expect(testResults?.testsPassed).toEqual(1);
82+
jestLib.expect(testResults?.totalTests).toEqual(2);
83+
jestLib.expect(testResults?.testsPassed).toEqual(2);
7284
jestLib.expect(testResults?.testsFailed).toEqual(0);
7385
jestLib.expect(testResults?.testsSkipped).toEqual(0);
7486
});
@@ -91,6 +103,26 @@ jestLib.describe(`Unit Testing ${testAssetWorkspace.description}`, function () {
91103
jestLib.expect(testResults?.testsFailed).toEqual(0);
92104
jestLib.expect(testResults?.testsSkipped).toEqual(0);
93105
});
106+
107+
jestLib.test('Run tests uses .runsettings', async () => {
108+
await setConfigurationAndWaitForObserver('dotnet.unitTests.runSettingsPath', '.runsettings');
109+
110+
const codeLenses = await getCodeLensesAsync();
111+
jestLib.expect(codeLenses).toHaveLength(9);
112+
113+
const runAllTestsCommand = codeLenses[2].command!;
114+
jestLib.expect(runAllTestsCommand.title).toBe('Run All Tests');
115+
116+
const testResults = await vscode.commands.executeCommand<TestProgress | undefined>(
117+
runAllTestsCommand.command,
118+
runAllTestsCommand.arguments![0]
119+
);
120+
jestLib.expect(testResults).toBeDefined();
121+
jestLib.expect(testResults?.totalTests).toEqual(1);
122+
jestLib.expect(testResults?.testsPassed).toEqual(1);
123+
jestLib.expect(testResults?.testsFailed).toEqual(0);
124+
jestLib.expect(testResults?.testsSkipped).toEqual(0);
125+
});
94126
});
95127

96128
async function getCodeLensesAsync(): Promise<vscode.CodeLens[]> {
@@ -118,3 +150,15 @@ async function getCodeLensesAsync(): Promise<vscode.CodeLens[]> {
118150
return a.command!.title.localeCompare(b.command!.command);
119151
});
120152
}
153+
154+
async function setConfigurationAndWaitForObserver<T>(configuration: string, value: T): Promise<void> {
155+
const changed = new Promise<void>((resolve, _) => {
156+
vscode.workspace.onDidChangeConfiguration((e) => {
157+
if (e.affectsConfiguration(configuration)) {
158+
resolve();
159+
}
160+
});
161+
});
162+
vscode.workspace.getConfiguration().update(configuration, value);
163+
await changed;
164+
}

0 commit comments

Comments
 (0)