Skip to content

Commit ce95719

Browse files
authored
Merge pull request #2416 from akshita31/class_name
Add class name to the run/debug all tests
2 parents 28645b2 + 8d2bf8f commit ce95719

File tree

6 files changed

+57
-20
lines changed

6 files changed

+57
-20
lines changed

src/features/codeLensProvider.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ abstract class TestCodeLens extends OmniSharpCodeLens {
4141
constructor(
4242
range: protocol.V2.Range,
4343
fileName: string,
44+
public displayName: string,
4445
public isTestContainer: boolean,
4546
public testFramework: string,
4647
public testMethodNames: string[]) {
@@ -53,23 +54,25 @@ class RunTestsCodeLens extends TestCodeLens {
5354
constructor(
5455
range: protocol.V2.Range,
5556
fileName: string,
57+
displayName: string,
5658
isTestContainer: boolean,
5759
testFramework: string,
5860
testMethodNames: string[]) {
5961

60-
super(range, fileName, isTestContainer, testFramework, testMethodNames);
62+
super(range, fileName, displayName, isTestContainer, testFramework, testMethodNames);
6163
}
6264
}
6365

6466
class DebugTestsCodeLens extends TestCodeLens {
6567
constructor(
6668
range: protocol.V2.Range,
6769
fileName: string,
70+
displayName: string,
6871
isTestContainer: boolean,
6972
testFramework: string,
7073
testMethodNames: string[]) {
7174

72-
super(range, fileName, isTestContainer, testFramework, testMethodNames);
75+
super(range, fileName, displayName, isTestContainer, testFramework, testMethodNames);
7376
}
7477
}
7578

@@ -152,7 +155,7 @@ export default class OmniSharpCodeLensProvider extends AbstractProvider implemen
152155
codeLens.command = {
153156
title: pluralTitle,
154157
command: pluralCommandName,
155-
arguments: [codeLens.testMethodNames, codeLens.fileName, codeLens.testFramework]
158+
arguments: [codeLens.displayName, codeLens.testMethodNames, codeLens.fileName, codeLens.testFramework]
156159
};
157160
}
158161

@@ -188,8 +191,8 @@ function createCodeLensesForElement(element: Structure.CodeElement, fileName: st
188191
let range = element.Ranges[SymbolRangeNames.Name];
189192

190193
if (range && testFramework && testMethodName) {
191-
results.push(new RunTestsCodeLens(range, fileName, /*isTestContainer*/ false, testFramework, [testMethodName]));
192-
results.push(new DebugTestsCodeLens(range, fileName, /*isTestContainer*/ false, testFramework, [testMethodName]));
194+
results.push(new RunTestsCodeLens(range, fileName, element.DisplayName,/*isTestContainer*/ false, testFramework, [testMethodName]));
195+
results.push(new DebugTestsCodeLens(range, fileName, element.DisplayName,/*isTestContainer*/ false, testFramework, [testMethodName]));
193196
}
194197
}
195198
else if (isValidClassForTestCodeLens(element)) {
@@ -210,8 +213,8 @@ function createCodeLensesForElement(element: Structure.CodeElement, fileName: st
210213
}
211214
}
212215

213-
results.push(new RunTestsCodeLens(range, fileName, /*isTestContainer*/ true, testFramework, testMethodNames));
214-
results.push(new DebugTestsCodeLens(range, fileName, /*isTestContainer*/ true, testFramework, testMethodNames));
216+
results.push(new RunTestsCodeLens(range, fileName, element.DisplayName,/*isTestContainer*/ true, testFramework, testMethodNames));
217+
results.push(new DebugTestsCodeLens(range, fileName, element.DisplayName,/*isTestContainer*/ true, testFramework, testMethodNames));
215218
}
216219
}
217220

src/features/dotnetTest.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ export default class TestManager extends AbstractProvider {
4343

4444
let d4 = vscode.commands.registerCommand(
4545
'dotnet.classTests.run',
46-
async (methodsInClass, fileName, testFrameworkName) => this._runDotnetTestsInClass(methodsInClass, fileName, testFrameworkName));
46+
async (className, methodsInClass, fileName, testFrameworkName) => this._runDotnetTestsInClass(className, methodsInClass, fileName, testFrameworkName));
4747

4848
let d5 = vscode.commands.registerCommand(
4949
'dotnet.classTests.debug',
50-
async (methodsInClass, fileName, testFrameworkName) => this._debugDotnetTestsInClass(methodsInClass, fileName, testFrameworkName));
50+
async (className, methodsInClass, fileName, testFrameworkName) => this._debugDotnetTestsInClass(className, methodsInClass, fileName, testFrameworkName));
5151

5252
this._telemetryIntervalId = setInterval(() =>
5353
this._reportTelemetry(), TelemetryReportingDelay);
@@ -164,10 +164,10 @@ export default class TestManager extends AbstractProvider {
164164
}
165165
}
166166

167-
private async _runDotnetTestsInClass(methodsInClass: string[], fileName: string, testFrameworkName: string) {
167+
private async _runDotnetTestsInClass(className: string, methodsInClass: string[], fileName: string, testFrameworkName: string) {
168168

169169
//to do: try to get the class name here
170-
this._eventStream.post(new DotNetTestsInClassRunStart());
170+
this._eventStream.post(new DotNetTestsInClassRunStart(className));
171171

172172
const listener = this._server.onTestMessage(e => {
173173
this._eventStream.post(new DotNetTestMessage(e.Message));
@@ -346,9 +346,9 @@ export default class TestManager extends AbstractProvider {
346346
}
347347
}
348348

349-
private async _debugDotnetTestsInClass(methodsToRun: string[], fileName: string, testFrameworkName: string) {
349+
private async _debugDotnetTestsInClass(className: string, methodsToRun: string[], fileName: string, testFrameworkName: string) {
350350

351-
this._eventStream.post(new DotNetTestsInClassDebugStart());
351+
this._eventStream.post(new DotNetTestsInClassDebugStart(className));
352352

353353
let { debugType, debugEventListener, targetFrameworkVersion } = await this._recordDebugAndGetDebugValues(fileName, testFrameworkName);
354354

src/observers/DotnetTestLoggerObserver.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { BaseEvent, DotNetTestRunStart, DotNetTestMessage, ReportDotNetTestResults, DotNetTestDebugStart, DotNetTestDebugWarning, DotNetTestDebugProcessStart, DotNetTestDebugComplete } from "../omnisharp/loggingEvents";
6+
import { BaseEvent, DotNetTestRunStart, DotNetTestMessage, ReportDotNetTestResults, DotNetTestDebugStart, DotNetTestDebugWarning, DotNetTestDebugProcessStart, DotNetTestDebugComplete, DotNetTestsInClassDebugStart, DotNetTestsInClassRunStart } from "../omnisharp/loggingEvents";
77
import { BaseLoggerObserver } from "./BaseLoggerObserver";
88
import * as protocol from '../omnisharp/protocol';
99

@@ -32,6 +32,12 @@ export default class DotNetTestLoggerObserver extends BaseLoggerObserver {
3232
case DotNetTestDebugComplete.name:
3333
this.logger.appendLine("Debugging complete.\n");
3434
break;
35+
case DotNetTestsInClassDebugStart.name:
36+
this.handleDotnetTestsInClassDebugStart(<DotNetTestsInClassDebugStart>event);
37+
break;
38+
case DotNetTestsInClassRunStart.name:
39+
this.handleDotnetTestsInClassRunStart(<DotNetTestsInClassRunStart>event);
40+
break;
3541
}
3642
}
3743

@@ -49,6 +55,16 @@ export default class DotNetTestLoggerObserver extends BaseLoggerObserver {
4955
this.logger.appendLine('');
5056
}
5157

58+
private handleDotnetTestsInClassDebugStart(event: DotNetTestsInClassDebugStart) {
59+
this.logger.appendLine(`----- Debugging tests in class ${event.className} -----`);
60+
this.logger.appendLine('');
61+
}
62+
63+
private handleDotnetTestsInClassRunStart(event: DotNetTestsInClassRunStart): any {
64+
this.logger.appendLine(`----- Running tests in class "${event.className}" -----`);
65+
this.logger.appendLine('');
66+
}
67+
5268
private handleDotNetTestDebugProcessStart(event: DotNetTestDebugProcessStart) {
5369
this.logger.appendLine(`Started debugging process #${event.targetProcessId}.`);
5470
}

src/omnisharp/loggingEvents.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ export class DotNetTestDebugProcessStart implements BaseEvent {
138138
constructor(public targetProcessId: number) { }
139139
}
140140

141+
142+
export class DotNetTestsInClassRunStart implements BaseEvent {
143+
constructor(public className: string) { }
144+
}
145+
146+
export class DotNetTestsInClassDebugStart implements BaseEvent {
147+
constructor(public className: string) { }
148+
}
149+
141150
export class DebuggerPrerequisiteFailure extends EventWithMessage { }
142151
export class DebuggerPrerequisiteWarning extends EventWithMessage { }
143152
export class CommandDotNetRestoreProgress extends EventWithMessage { }
@@ -168,6 +177,4 @@ export class OmnisharpServerOnStop implements BaseEvent { }
168177
export class OmnisharpServerOnStart implements BaseEvent { }
169178
export class LatestBuildDownloadStart implements BaseEvent { }
170179
export class OmnisharpRestart implements BaseEvent { }
171-
export class DotNetTestsInClassRunStart implements BaseEvent { }
172-
export class DotNetTestsInClassDebugStart implements BaseEvent { }
173180
export class DotNetTestDebugComplete implements BaseEvent { }

test/unitTests/logging/DotnetTestChannelObserver.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ suite("DotnetTestChannelObserver", () => {
2323
[
2424
new DotNetTestRunStart("foo"),
2525
new DotNetTestRunFailure("some failure"),
26-
new DotNetTestsInClassRunStart(),
26+
new DotNetTestsInClassRunStart("someclass"),
2727
new DotNetTestDebugStart("foo"),
28-
new DotNetTestsInClassDebugStart()
28+
new DotNetTestsInClassDebugStart("someclass")
2929
].forEach((event: BaseEvent) => {
3030
test(`${event.constructor.name}: Channel is shown`, () => {
3131
expect(hasShown).to.be.false;

test/unitTests/logging/DotnetTestLoggerObserver.test.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as chai from 'chai';
77
import { getNullChannel } from '../testAssets/Fakes';
8-
import { EventWithMessage, DotNetTestDebugWarning, DotNetTestDebugStart, BaseEvent, DotNetTestRunStart, DotNetTestDebugProcessStart, DotNetTestMessage, DotNetTestDebugComplete, ReportDotNetTestResults } from '../../../src/omnisharp/loggingEvents';
8+
import { EventWithMessage, DotNetTestDebugWarning, DotNetTestDebugStart, BaseEvent, DotNetTestRunStart, DotNetTestDebugProcessStart, DotNetTestMessage, DotNetTestDebugComplete, ReportDotNetTestResults, DotNetTestsInClassDebugStart, DotNetTestsInClassRunStart } from '../../../src/omnisharp/loggingEvents';
99
import DotNetTestLoggerObserver from '../../../src/observers/DotnetTestLoggerObserver';
1010
import * as protocol from '../../../src/omnisharp/protocol';
1111

@@ -42,7 +42,18 @@ suite(`${DotNetTestLoggerObserver.name}`, () => {
4242
observer.post(event);
4343
expect(appendedMessage).to.contain("foo");
4444
});
45-
});
45+
});
46+
47+
[
48+
new DotNetTestsInClassDebugStart("foo"),
49+
new DotNetTestsInClassRunStart("foo")
50+
].forEach((event: BaseEvent) => {
51+
test(`${event.constructor.name}: Class name is logged`, () => {
52+
expect(appendedMessage).to.be.empty;
53+
observer.post(event);
54+
expect(appendedMessage).to.contain("foo");
55+
});
56+
});
4657

4758
test(`${DotNetTestDebugProcessStart.name}: Target process id is logged`, () => {
4859
let event = new DotNetTestDebugProcessStart(111);

0 commit comments

Comments
 (0)