-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Endpoints for running and debugging all tests in a class #1089
Conversation
Omnisharp-vscode side : dotnet/vscode-csharp#1961 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some questions
@@ -78,10 +78,14 @@ public void EndSession() | |||
} | |||
|
|||
public Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string methodName, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) | |||
=> DebugGetStartInfoAsync(new string[] { methodName }, testFrameworkName, targetFrameworkVersion, cancellationToken); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra blank line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed that.
[OmniSharpEndpoint(OmniSharpEndpoints.V2.DebugTestsInClassGetStartInfo, typeof(DebugTestClassGetStartInfoRequest), typeof(DebugTestGetStartInfoResponse))] | ||
class DebugTestClassGetStartInfoRequest : Request | ||
{ | ||
public string[] MethodsInClass { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is just a list of methods, what happens if someone passes methods that aren't all in the same class?
namespace OmniSharp.DotNetTest.Models | ||
{ | ||
[OmniSharpEndpoint(OmniSharpEndpoints.V2.RunAllTestsInClass, typeof(RunTestsInClassRequest), typeof(RunTestResponse[]))] | ||
public class RunTestsInClassRequest : Request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this could share a base class with the DebugTests request (they're identical, no?)
@@ -76,6 +76,11 @@ public static TestManager Create(Project project, DotNetCliService dotNetCli, IE | |||
public abstract GetTestStartInfoResponse GetTestStartInfo(string methodName, string testFrameworkName, string targetFrameworkVersion); | |||
|
|||
public abstract Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string methodName, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken); | |||
|
|||
public virtual Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string[] methodNames, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What other types derive from TestManager? Should they implement this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's just two -- a legacy one for the old 'dotnet test' on project.json projects and the current 'dotnet vstest' version. I would only expect us to make this work for the newer stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have implemented this function only for the VSTestManager and not LegacyTestManager. Is that required ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the behavior if you open a project with legacy tests? Does the run tests
button show up? If it does, and you click it, what happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A project with legacy tests == a project.json project. I don't think we should invest effort in that. So long as we don't break the ability to run/debug a single test in a project.json project, I don't think we need to make any changes to LegacyTestManager
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I'm happy with our solution of not showing the indicator for legacy projects.
{ | ||
VerifyTestFramework(testFrameworkName); | ||
|
||
var testCases = await DiscoverTestsAsync(methodName, targetFrameworkVersion, cancellationToken); | ||
var testCases = new List<TestCase>(); | ||
foreach(var methodName in methodNames) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting:
foreach (....)
{
//stuff
}
namespace OmniSharp.DotNetTest.Services | ||
{ | ||
[OmniSharpHandler(OmniSharpEndpoints.V2.RunAllTestsInClass, LanguageNames.CSharp)] | ||
internal class RunTestsInClassService : BaseTestService<RunTestsInClassRequest, RunTestResponse[]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How similar is this to the class that runs a single test in a class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the same now, only the type of request differs. For one it is RunTestRequest and for the other it is RunTestInClassRequest and the corresponding fields - MethodName
and MethodNames
also differ.
@@ -78,10 +78,14 @@ public void EndSession() | |||
} | |||
|
|||
public Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string methodName, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) | |||
=> DebugGetStartInfoAsync(new string[] { methodName }, testFrameworkName, targetFrameworkVersion, cancellationToken); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it?
if (testManager.IsConnected) | ||
{ | ||
foreach (var methodName in request.MethodNames) | ||
responses.Add(testManager.RunTest(methodName, request.TestFrameworkName, request.TargetFrameworkVersion)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a method that can run tests in bulk (taking several method names) rather than looping through the tests and running them individually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect running several tests at once to be faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at what you've done with DebugGetStartInfoAsync
in VSTestManager
, I think you should probably do the same for RunTest
.
@@ -76,6 +76,11 @@ public static TestManager Create(Project project, DotNetCliService dotNetCli, IE | |||
public abstract GetTestStartInfoResponse GetTestStartInfo(string methodName, string testFrameworkName, string targetFrameworkVersion); | |||
|
|||
public abstract Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string methodName, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken); | |||
|
|||
public virtual Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string[] methodNames, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's just two -- a legacy one for the old 'dotnet test' on project.json projects and the current 'dotnet vstest' version. I would only expect us to make this work for the newer stuff.
public virtual Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string[] methodNames, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) | ||
{ | ||
throw new NotImplementedException(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing blank line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you confirm the legacy behavior if the button shows up? Otherwise looks good
: base(workspace, dotNetCli, eventEmitter, loggerFactory) | ||
{ | ||
_debugSessionManager = debugSessionManager; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a blank line.
|
||
protected override RunTestResponse HandleRequest(RunTestsInClassRequest request, TestManager testManager) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra blank line
@@ -76,6 +76,11 @@ public static TestManager Create(Project project, DotNetCliService dotNetCli, IE | |||
public abstract GetTestStartInfoResponse GetTestStartInfo(string methodName, string testFrameworkName, string targetFrameworkVersion); | |||
|
|||
public abstract Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string methodName, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken); | |||
|
|||
public virtual Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string[] methodNames, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the behavior if you open a project with legacy tests? Does the run tests
button show up? If it does, and you click it, what happens?
@@ -184,10 +191,19 @@ public override GetTestStartInfoResponse GetTestStartInfo(string methodName, str | |||
} | |||
|
|||
public override RunTestResponse RunTest(string methodName, string testFrameworkName, string targetFrameworkVersion) | |||
=> RunTest(new string[] { methodName }, testFrameworkName, targetFrameworkVersion); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent
var testCasesList = new List<TestCase>(); | ||
foreach (var methodName in methodNames) | ||
{ | ||
testCasesList.AddRange(DiscoverTests(methodName, targetFrameworkVersion)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will cause test discovery to be performed for every method in the class, which is unnecessarily slow. Could you update DiscoverTests
to take multiple method names?
@@ -302,7 +292,7 @@ public override RunTestResponse RunTest(string[] methodNames, string testFramewo | |||
|
|||
testName = testName.Trim(); | |||
|
|||
if (testName.Equals(methodName, StringComparison.Ordinal)) | |||
if (Array.Exists(methodNames, methodName => testName.Equals(methodName, StringComparison.Ordinal))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: If you want to remove the O(n) operation here, you could add the method names to a HashSet<string>(StringComparison.Ordinal)
and test that for containership here.
The "run all tests" and "debug all tests" codelens will appear only for the MsBuild type project system and not for the legacy projects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM--thanks!
{ | ||
public string[] MethodNames { get; set; } | ||
public string TestFrameworkName { get; set; } | ||
/// <summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above the doc comment
@@ -76,6 +76,11 @@ public static TestManager Create(Project project, DotNetCliService dotNetCli, IE | |||
public abstract GetTestStartInfoResponse GetTestStartInfo(string methodName, string testFrameworkName, string targetFrameworkVersion); | |||
|
|||
public abstract Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string methodName, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken); | |||
|
|||
public virtual Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string[] methodNames, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I'm happy with our solution of not showing the indicator for legacy projects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me!
Added endpoints to enable "Run All Tests" in class and "Debug All Tests" in class
Please review : @DustinCampbell @rchande @TheRealPiotrP @filipw