testing method which create a new thread and result we get from event ( NUnit 2.6 )

后端 未结 4 647
别那么骄傲
别那么骄傲 2021-02-10 01:26

I have class which have one public method Start, one private method and one event Finishing. Start call new Thread( private_method )

4条回答
  •  暖寄归人
    2021-02-10 01:43

    NUnit has built-in feature for waiting for assertion. It is called 'After':

    [Test]
    public void ShouldRaiseFinishedEvent()
    {
        SomeClass someObject = new SomeClass();
        bool eventRaised = false;
        someObject.SomethingFinished += (o, e) => { eventRaised = true; };
    
        someObject.DoSomething();
        Assert.That(eventRaised, Is.True.After(500));
    }
    

提交回复
热议问题