Skip to content

Commit

Permalink
Merge pull request #6336 from dibarbet/runsettings_integration_test
Browse files Browse the repository at this point in the history
Add integration test for .runsettings in unit tests
  • Loading branch information
dibarbet authored Sep 11, 2023
2 parents 058368b + 5d3a063 commit 17ef56a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ suite(`CodeLensProvider options: ${testAssetWorkspace.description}`, function ()
await csharpConfig.update('codeLens.enableTestsCodeLens', false);

const codeLenses = await GetCodeLenses(fileUri, 100);
expect(codeLenses.length).to.equal(2);
expect(codeLenses.length).to.equal(3);

for (const codeLens of codeLenses) {
expect(codeLens.isResolved).to.be.true;
Expand Down
5 changes: 5 additions & 0 deletions test/integrationTests/testAssets/slnWithCsproj/.runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RunSettings>
<RunConfiguration>
<TestCaseFilter>TestCategory=include</TestCaseFilter>
</RunConfiguration>
</RunSettings>
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@ public void Test1()
{

}

[Fact]
[Trait("TestCategory", "include")]
public void Test2()
{

}
}
}
60 changes: 52 additions & 8 deletions test/integrationTests/unitTests.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jestLib.describe(`Unit Testing ${testAssetWorkspace.description}`, function () {
});

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

jestLib.test('Unit test code lens items are displayed', async () => {
const codeLenses = await getCodeLensesAsync();
jestLib.expect(codeLenses).toHaveLength(6);
jestLib.expect(codeLenses).toHaveLength(9);

const classRange = new vscode.Range(new vscode.Position(5, 17), new vscode.Position(5, 26));

// Class level debug all tests
jestLib.expect(codeLenses[1].command?.command).toBe('dotnet.test.run');
jestLib.expect(codeLenses[1].command?.title).toBe('Debug All Tests');
Expand All @@ -41,23 +45,31 @@ jestLib.describe(`Unit Testing ${testAssetWorkspace.description}`, function () {
jestLib.expect(codeLenses[2].command?.arguments![0].attachDebugger).toBe(false);
jestLib.expect(codeLenses[2].range).toStrictEqual(classRange);

const methodRange = new vscode.Range(new vscode.Position(8, 20), new vscode.Position(8, 25));
// Method level debug test
let methodRange = new vscode.Range(new vscode.Position(8, 20), new vscode.Position(8, 25));
// Method level run and debug test
jestLib.expect(codeLenses[4].command?.command).toBe('dotnet.test.run');
jestLib.expect(codeLenses[4].command?.title).toBe('Debug Test');
jestLib.expect(codeLenses[4].command?.arguments![0].attachDebugger).toBe(true);
jestLib.expect(codeLenses[4].range).toStrictEqual(methodRange);

// Method level run test
jestLib.expect(codeLenses[5].command?.command).toBe('dotnet.test.run');
jestLib.expect(codeLenses[5].command?.title).toBe('Run Test');
jestLib.expect(codeLenses[5].command?.arguments![0].attachDebugger).toBe(false);
jestLib.expect(codeLenses[5].range).toStrictEqual(methodRange);

methodRange = new vscode.Range(new vscode.Position(15, 20), new vscode.Position(15, 25));
jestLib.expect(codeLenses[7].command?.command).toBe('dotnet.test.run');
jestLib.expect(codeLenses[7].command?.title).toBe('Debug Test');
jestLib.expect(codeLenses[7].command?.arguments![0].attachDebugger).toBe(true);
jestLib.expect(codeLenses[7].range).toStrictEqual(methodRange);
jestLib.expect(codeLenses[8].command?.command).toBe('dotnet.test.run');
jestLib.expect(codeLenses[8].command?.title).toBe('Run Test');
jestLib.expect(codeLenses[8].command?.arguments![0].attachDebugger).toBe(false);
jestLib.expect(codeLenses[8].range).toStrictEqual(methodRange);
});

jestLib.test('Code lens command executes tests', async () => {
const codeLenses = await getCodeLensesAsync();
jestLib.expect(codeLenses).toHaveLength(6);
jestLib.expect(codeLenses).toHaveLength(9);

const runAllTestsCommand = codeLenses[2].command!;
jestLib.expect(runAllTestsCommand.title).toBe('Run All Tests');
Expand All @@ -67,8 +79,8 @@ jestLib.describe(`Unit Testing ${testAssetWorkspace.description}`, function () {
runAllTestsCommand.arguments![0]
);
jestLib.expect(testResults).toBeDefined();
jestLib.expect(testResults?.totalTests).toEqual(1);
jestLib.expect(testResults?.testsPassed).toEqual(1);
jestLib.expect(testResults?.totalTests).toEqual(2);
jestLib.expect(testResults?.testsPassed).toEqual(2);
jestLib.expect(testResults?.testsFailed).toEqual(0);
jestLib.expect(testResults?.testsSkipped).toEqual(0);
});
Expand All @@ -91,6 +103,26 @@ jestLib.describe(`Unit Testing ${testAssetWorkspace.description}`, function () {
jestLib.expect(testResults?.testsFailed).toEqual(0);
jestLib.expect(testResults?.testsSkipped).toEqual(0);
});

jestLib.test('Run tests uses .runsettings', async () => {
await setConfigurationAndWaitForObserver('dotnet.unitTests.runSettingsPath', '.runsettings');

const codeLenses = await getCodeLensesAsync();
jestLib.expect(codeLenses).toHaveLength(9);

const runAllTestsCommand = codeLenses[2].command!;
jestLib.expect(runAllTestsCommand.title).toBe('Run All Tests');

const testResults = await vscode.commands.executeCommand<TestProgress | undefined>(
runAllTestsCommand.command,
runAllTestsCommand.arguments![0]
);
jestLib.expect(testResults).toBeDefined();
jestLib.expect(testResults?.totalTests).toEqual(1);
jestLib.expect(testResults?.testsPassed).toEqual(1);
jestLib.expect(testResults?.testsFailed).toEqual(0);
jestLib.expect(testResults?.testsSkipped).toEqual(0);
});
});

async function getCodeLensesAsync(): Promise<vscode.CodeLens[]> {
Expand Down Expand Up @@ -118,3 +150,15 @@ async function getCodeLensesAsync(): Promise<vscode.CodeLens[]> {
return a.command!.title.localeCompare(b.command!.command);
});
}

async function setConfigurationAndWaitForObserver<T>(configuration: string, value: T): Promise<void> {
const changed = new Promise<void>((resolve, _) => {
vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration(configuration)) {
resolve();
}
});
});
vscode.workspace.getConfiguration().update(configuration, value);
await changed;
}

0 comments on commit 17ef56a

Please sign in to comment.