Cannot find Assert.Fail and Assert.Pass or equivalent

后端 未结 4 989
太阳男子
太阳男子 2021-02-04 23:05

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;//woul         


        
4条回答
  •  梦毁少年i
    2021-02-04 23:53

    An alternative to Assert.Fail("messsage") suggested by xUnit docs

    xUnit.net alternative: Assert.True(false, "message")

    has a downside – its output is

    message
    
    Expected: True
    Actual:   False
    

    To get rid of

    Expected: True
    Actual:   False
    

    don't call Assert.True(false, "message") throw Xunit.Sdk.XunitException instead.
    For example, create a helper method similar to this:

    public static class MyAssert
    {
        public static void Fail(string message)
            => throw new Xunit.Sdk.XunitException(message);
    }
    

提交回复
热议问题