[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);
}
单元测试失败,因为这些方法是异步的。
字符串test
为“NULL”,因为值test2
稍后出现。我该如何解决这个问题呢?
答案 0 :(得分:0)
有几种选择:
Assert.AreEqual
之前,您可以插入Thread.Sleep(MaxTimeoutForEvent)
P.S。请记住TestCleanup
:)