Unit Test asynchronous event handler

[TestInitialize]
public void Initialize()
{
    //DO Something
    async_eventhandler += the_eventhandler(async_eventhandler);
}

private void async_eventhandler
{
test = test2
    // test2 comes from client, after here TestMethod have to start
}

[TestMethod]
public void TestMethod1()
{
    Assert.AreEqual("test_test", test);
}

      

Unit Test failed because the methods are asynchronous. The string test

is "NULL" because the value test2

will appear later. How can I solve the problem?

+3


source to share


1 answer


There are several options:

  • Until Assert.AreEqual

    you can insertThread.Sleep(MaxTimeoutForEvent)

  • Use delayed assert. An example can be found in this question


PS Remember TestCleanup

:)

0


source







All Articles