1

I wanted to unit-test an abstract class by creating abstract test-class with abstract factory method (using this approach) that polymorphically gets the concrete instance. Something like this:

public abstract class Base
{
  public bool MyMethod()
  {
    return true;
  }
}

public class Derived : Base {}

// Tests

public abstract class BaseTest
{
  [Fact]
  public void MyMethod_MakeTestFailByAssertingFalseReturn()
  {
    //Arrange
    var instance = GetConcreteInstance();

    //Act
    bool result = instance.MyMethod();

    //Assert
    Assert.False(result);
  }

  protected abstract Base GetConcreteInstance();
}

public class DerivedTest : BaseTest
{
  protected override Base GetConcreteInstance()
  {
    return new Derived();
  }
}

So far, so good. But ReSharper test runner gives this error:

Inconclusive: Test wasn't run

for all tests inside BaseTest class. Even the ones that are ignored. I tried to run the tests with Visual Studio test runner, but it doesn't detect any of them.

ebu_sho
  • 394
  • 6
  • 17
  • Did you add the `TestAttribute` to your test-methods as well as `TestFixtureAttribute` to your class? Be aware that those aren´t inherited to your `DerivedTest`-class. – MakePeaceGreatAgain Dec 12 '17 at 07:38
  • Yes, I have `[Fact]` attributes to my test methods. `TestFixtureAttribute` is not required for xUnit, as i'ts stated on their site: _xUnit.net does not require an attribute for a test class; it looks for all test methods in all public (exported) classes in the assembly._ ( https://xunit.github.io/docs/comparisons.html ) – ebu_sho Dec 12 '17 at 07:49
  • 1
    Make your sample actually accurate - i.e. don't talk about `[Fact]`, put it in! – Ruben Bartelink Dec 12 '17 at 09:23
  • The code looks correct, which _should_ make it a discovery issue - I have a [checklist self-answer question](https://stackoverflow.com/questions/35103781/why-is-the-visual-studio-2015-2017-test-runner-not-discovering-my-xunit-v2-tests/47574982#47574982) and [another](https://stackoverflow.com/q/16214684/11635) which might help - step one is to see if you can make a fresh test project in a fresh solution work in R# and/or VS to try to narrow it down. (If not using latest xunit, might be worth mentioning that, also if not referencing `xunit.runner.visualstudio`, vs runner should not work) – Ruben Bartelink Dec 13 '17 at 00:21

1 Answers1

0

You can check this. Also i had problems with text explorer that didnt find my tests, i manage to fix the problem when i delete a temp visualstudioextension directory which you can find at path - C:/users/USERNAME/AppData/Local/Temp/VisualStudioTestExplorerExtensions.