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.
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With