开发者

How to cause a Test Run Error if AssemblyCleanup times out?

I'm using MSTest in Visual Studio 2010 and have the need to restore my dat开发者_运维问答abase after all tests have run.

What I did was decorate a method with the AssemblyCleanupAttribute attribute.

<AssemblyCleanupAttribute()>
Shared Sub AssemblyCleanup()
    ' Restore my databases which takes a long time...
End Sub

Problem is the clean up takes a reasonable amount of time, so much so that the timeout is reached.

The only reason I started realizing that a timeout occurred is that in debug mode the Output window reports "...QTAgent32.exe, AgentObject: Cleanup: Timeout reached in cleaning up the agent.". Hence it fails very quietly and I would have loved if MSTest reported a Test Run Error.

What is the best way to detect and report the timeout? My ideal solution would be to report the timeout as a test run error.


In short, you cannot cause MSTest to report an error if AssemblyCleanup times out.

If you are encountering this issue, then at this point you need to consider if this limitation of MSTest is too great for you. There are other, and imho better, test frameworks out there.

If you decide to stick with MSTest and just want to ensure, at least, that the code/script in AssemblyCleanup runs to completion then you can choose to either run the clean up code as a Process. That way even if AssemblyCleanup internally calls a Thread.Abort then your Process runs to completion. It's messy though...


Why not wrap the contents of each test in a transaction, and rollback the transaction at the end of the test? See here for more information: http://msdn.microsoft.com/en-us/library/bb381703(v=vs.80).aspx#dtbunttsttedp_topic7

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜