Delayed NUnit Assert message evaluation

后端 未结 3 1020
广开言路
广开言路 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:26

    In NUnit version 3.50 I had to use a different syntax. Here is the example:

    var constraint = Is.True.After( delayInMilliseconds: 100000, pollingInterval: 100);
    Assert.That( () => yourCondition, constraint );
    


    This will test whether yourCondition is true waiting a certain maximum time using the DelayedConstraint created by the Is.True.After method.

    In this example the DelayedConstraint is configured to use maximum time of 100 seconds polling every 0.1 seconds.

    See aslo the legacy NUnit 2.5 documentation for DelayedConstraint.

提交回复
热议问题