Delayed NUnit Assert message evaluation

后端 未结 3 1021
广开言路
广开言路 2021-02-20 10:09

I have this assert in my test code

Assert.That(() => eventData.Count == 0,
Is.True.After(notificationPollingDelay),
\"Received unexpected event with last even         


        
3条回答
  •  滥情空心
    2021-02-20 10:31

    The simplest answer is "don't include that text in your failure message". I personally almost never include a failure message; if your test is atomic enough you don't need to do it. Usually if I need to figure out a cryptic failure, only a debugger helps anyway.

    If you really want to do it, this code should work without managing the threads yourself.

    try
    {
        Assert.That(() => eventData.Count == 0, Is.True.After(notificationPollingDelay));
    }
    catch(AssertionException)
    {
        throw new Exception("Received unexpected event with last event data" + eventData.Last().Description());
    }
    

提交回复
热议问题