Skip to content
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

Merged
merged 16 commits into from
Jan 29, 2018

Conversation

akshita31
Copy link
Contributor

@akshita31 akshita31 commented Jan 13, 2018

Added endpoints to enable "Run All Tests" in class and "Debug All Tests" in class

Please review : @DustinCampbell @rchande @TheRealPiotrP @filipw

@akshita31
Copy link
Contributor Author

Omnisharp-vscode side : dotnet/vscode-csharp#1961

Copy link

@rchande rchande left a 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);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it?

Copy link
Contributor Author

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; }
Copy link

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
Copy link

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)
Copy link

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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 ?

Copy link

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?

Copy link
Contributor

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.

Copy link

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)
Copy link

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[]>
Copy link

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?

Copy link
Contributor Author

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);

Copy link
Contributor

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));
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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)
Copy link
Contributor

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();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing blank line.

Copy link

@rchande rchande left a 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;
}
Copy link

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)
{

Copy link

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)
Copy link

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);
Copy link

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));
Copy link
Contributor

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)))
Copy link
Contributor

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.

@akshita31
Copy link
Contributor Author

The "run all tests" and "debug all tests" codelens will appear only for the MsBuild type project system and not for the legacy projects.

Copy link

@rchande rchande left a 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>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where ?

Copy link

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)
Copy link

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.

Copy link
Contributor

@DustinCampbell DustinCampbell left a 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!

@rchande rchande merged commit 759f062 into OmniSharp:master Jan 29, 2018
@akshita31 akshita31 deleted the class_test branch January 29, 2018 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants