How to test the application of a Conditional Attribute in MSTest in Dotnet Core?

38 Views Asked by At

I have a factory class that has a private method like this:

[Conditional("DEBUG")]
private static void IsDebugCheck(ref bool isDebug)
{
    isDebug = true;
}

The logic is used later in the class like so to generate different implementations of the same interface, like this:

if (IsDebugCheck){
  return new ImplementationA();
}
else{
  return new ImplementationB();
}

I am trying to write unit tests for this now, and want to somehow set the conditional value within the test. I'm using MsTest for this and have been googlign and found no good information on how to do this.

[TestMethod()]
[TestCategory("Debug")]
public void FactoryShouldGenerateImplementationAIfInDebug()

[TestMethod()]
[TestCategory("Debug")]
public void FactoryShouldGenerateImplementationBIfInReleaseMode()

But so far have been utterly striking out on how to do this.

0

There are 0 best solutions below