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

"run test" command runs the wrong xunit test when two tests start with the same string. #1426

Closed
nozzlegear opened this issue Apr 25, 2017 · 2 comments
Assignees
Milestone

Comments

@nozzlegear
Copy link

Title might be a bit confusing, but to boil it down I have two xunit tests; one is named Catches_Rate_Limit, the other is named Catches_Rate_Limit_With_Base_Exception. When I click the run test button on Catches_Rate_Limit, OmniSharp actually runs the Catches_Rate_Limit_With_Base_Exception test.

sketch

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.1)

Product Information:
 Version:            1.0.1
 Commit SHA-1 hash:  005db40cd1

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.16170
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\1.0.1

VS Code version:
1.11.1

C# Extension version:
1.9.0

Steps to reproduce

  1. Create a new xunit test project: dotnet new xunit

  2. Create three tests. Name the first TestFoo, the second RandomTest, and the third TestFooBar:

public class UnitTest1
{
    [Fact]
    public void TestFoo()
    {
        Assert.True(false, $"{nameof(TestFoo)} was run.");
    }

    [Fact]
    public void RandomTest()
    {
        Assert.True(false, $"{nameof(RandomTest)} was run.");
    }

    [Fact]
    public void TestFooBar()
    {
        Assert.True(false, $"{nameof(TestFooBar)} was run.");
    }
}
  1. Click the run test button on TestFoo.

Expected behavior

VSCode should run the TestFoo test.

Actual behavior

VSCode runs both the TestFoo and TestFooBar tests and outputs this:

Running test omnisharp_tests.UnitTest1.TestFoo...
[xUnit.net 00:00:00.4517726]   Starting:    omnisharp-tests
[xUnit.net 00:00:00.6160937]     omnisharp_tests.UnitTest1.TestFoo [FAIL]
[xUnit.net 00:00:00.6170575]       TestFoo was run.
[xUnit.net 00:00:00.6171549]       Expected: True
[xUnit.net 00:00:00.6171882]       Actual:   False
[xUnit.net 00:00:00.6179641]       Stack Trace:
[xUnit.net 00:00:00.6188630]         d:\source\playgrounds\omnisharp-tests\UnitTest1.cs(11,0): at omnisharp_tests.UnitTest1.TestFoo()
[xUnit.net 00:00:00.6315508]     omnisharp_tests.UnitTest1.TestFooBar [FAIL]
[xUnit.net 00:00:00.6316562]       TestFooBar was run.
[xUnit.net 00:00:00.6316855]       Expected: True
[xUnit.net 00:00:00.6317343]       Actual:   False
[xUnit.net 00:00:00.6317850]       Stack Trace:
[xUnit.net 00:00:00.6318326]         d:\source\playgrounds\omnisharp-tests\UnitTest1.cs(17,0): at omnisharp_tests.UnitTest1.TestFooBar()
[xUnit.net 00:00:00.6333140]   Finished:    omnisharp-tests
Test failed 

Both the TestFoo and TestFooBar tests were run – something I wasn't able to reproduce in my original project where only the Catches_Rate_Limit_With_Base_Exception test would run.

The RandomTest test did not run at all, as expected.

@DustinCampbell
Copy link
Member

Good catch -- thanks! The bug is here: https://github.com/OmniSharp/omnisharp-roslyn/blob/dev/src/OmniSharp.DotNetTest/VSTestManager.cs#L248

This was written this way to properly handle theories (which can appear as multiple tests), but it's clear that this needs a bit of tweaking.

@DustinCampbell DustinCampbell added this to the 1.10 milestone Apr 25, 2017
@nozzlegear
Copy link
Author

Great, at least it was easy to pinpoint! I'd offer to help with a pull request, but I've only just started using Xunit and I don't know how the theories work yet. I'm not sure how they'd best be handled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants