Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xUnit Equivalent of MSTest's Assert.Inconclusive

What is the xUnit equivalent of the following MSTest code:

Assert.Inconclusive("Reason"); 

This gives a yellow test result instead of the usual green or red. I want to assert that the test could not be run due to certain conditions and that the test should be re-run after those conditions have been met.

like image 677
Muhammad Rehan Saeed Avatar asked Jan 05 '16 11:01

Muhammad Rehan Saeed


People also ask

What is assert inconclusive?

Assert.Inconclusive indicates that either: I have not yet written the test;I've only created the test method. -or- My test has a dependency and that dependency is not available.

How do I ignore test cases in xUnit?

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. Set the Skip parameter on the [Fact] attribute to temporarily skip a test.

Should I use MSTest or xUnit?

As far as NUnit vs. XUnit vs. MSTest is concerned, the biggest difference between xUnit and the other two test frameworks (NUnit and MSTest) is that xUnit is much more extensible when compared to NUnit and MSTest. The [Fact] attribute is used instead of the [Test] attribute.

How do I expect exception in xUnit?

If you do want to be rigid about AAA then you can use Record. Exception from xUnit to capture the Exception in your Act stage. You can then make assertions based on the captured exception in the Assert stage. An example of this can be seen in xUnits tests.


1 Answers

Best thing one can do until something is implemented in the library is to use Xunit.SkippableFact:

[SkippableFact] public void SomeTest() {     var canRunTest = CheckSomething();     Skip.IfNot(canRunTest);      // Normal test code } 

This will at least make it show up as a yellow ignored test case in the list.

Credit goes to https://stackoverflow.com/a/35871507/537842

like image 200
Anttu Avatar answered Oct 27 '22 21:10

Anttu