vscode-dotnet-test-explorer icon indicating copy to clipboard operation
vscode-dotnet-test-explorer copied to clipboard

Test Explorer Issues on Inheritance

Open keeed opened this issue 5 years ago • 7 comments

When you have something like this:

public abstract class TestTemplate { [Fact] public Task Some_Test() { ... } }

public class SomeTest : TestTemplate { ... }

Test Explorer can properly see that SomeTest contains a test called Some_Test. However, clicking on the test would show a warning "Could not find test".

keeed avatar May 06 '19 10:05 keeed

Closing this issue as putting the test on the base class makes it really hard to execute the "Debug Test" on vscode.

keeed avatar May 06 '19 13:05 keeed

I would actually appreciate a fix for this issue. Seems to be that OmniSharp doesn't have inherited members in the symbol list that it searches when provideWorkspaceSymbols() is called. I'm not sure if the solution is to have the dotnet test explorer provide a different string or if OmniSharp doesn't behave as expected.

bearrista avatar Jan 06 '20 19:01 bearrista

I think this should remain open - I use inherited classes in a lot of cases, especially when using inheritance in the code I am testing. This allows me to write tests that are applicable to all implementing classes a single time. Running the tests in the Test Explorer will run the tests in the base class and they show in the correct place, but I cannot run them by just clicking on them. This is extra annoying because I also can't use CodeLens to run them, so the only way to do so is to use dotnet test cli or to run tests in class in the Test Explorer, which only works like 1/4 the time.

garie avatar Apr 07 '20 01:04 garie

Hmm yea if I remember correctly it was Omnisharp that was unable to find the location of the symbol and since that is what we use to find the place to go to when clicking it was hard for us to solve it.

But maybe never versions of Omnisharp supports this better.

stefanforsberg avatar Apr 07 '20 12:04 stefanforsberg

I would love this to be fixed as well. I use a lot of inherited classes.

edobarnes avatar Mar 10 '21 17:03 edobarnes

Seems like omnisharp has changed since then.

The following two tests are now shown correctly under Concrete in the test explorer, and can be run successfully:

public abstract class Base {
  [Fact] public void test1() { }
  [Fact] public void test2() { }
}

public class Concrete : Base {
}

Obviously there are two limitations, which cannot be fixed:

  • debugging cannot be performed
  • one cannot use codelens to start tests

And there is one remaining bug:

  • Concrete will not run tests from Base in codelens (codelens is not even shown); but they can be run from the test explorer

lonix1 avatar Sep 15 '21 11:09 lonix1

Hello, is there any update ?

kconde2 avatar Mar 17 '23 17:03 kconde2