I used to use these in NUnit and they are really useful. Any idea how to do something like that?
EDIT, CODE SAMPLE:
bool condition = false;//would be nice not to have this
observable.Subscribe(_ =>
{
if (real test)
condition= true;//Assert.Pass()
});
StartObservable();
Assert.True(condition);//Assert.Fail()
An alternative to
Assert.Fail("messsage")
suggested by xUnit docshas a downside – its output is
To get rid of
don't call
Assert.True(false, "message")
throwXunit.Sdk.XunitException
instead.For example, create a helper method similar to this:
Just throw an exception to satisfy both requirements (exiting a nested loop and an alternative to the missing Assert.Fail method). Only issue is there is no decent base exception (e.g. TestException) to use in order to avoid getting warnings about using the base Exception class, so something more directed like an InvalidOperationException is probably a good choice.
The documentation includes a comparison chart including this:
(It doesn't show
Assert.Pass
, and I've never used that myself, but I suspect the alternative is just to return from the test. Of course that doesn't help if you want to throw it in a nested method call. My suspicion is that it's not very frequently used in NUnit, hence its absence in the comparison chart.)