Why is [AssemblyInitialize] and [AssemblyCleanup] being called twice in same test project assembly?

后端 未结 3 2158
长发绾君心
长发绾君心 2021-02-15 02:27

I thought the whole purpose of these attributes was to run them only once per assembly. I have a simple class as follows:

[TestClass]
public class AssemblyIntegr         


        
3条回答
  •  你的背包
    2021-02-15 03:02

    Well, this answer is a bazillion years late based on the original problem date but...

    I discovered if the test agent (QTAgent32.exe) crashes or dies before the complete sequence finishes, then AssemblyInitialize (and maybe ClassInitialize and TestInitialize) would be called again. For example, put this in your [AssemblyCleanup] function and you'll see the behavior occur:

    Process p = AutotestShared.RunProcess("cmd", "/c taskkill /t /f /im QTAgent32.exe", true);
    p.WaitForExit();
    

    So the moral of this story is: Check your cleanup functions to see if there are any crashes / corruption. Failures during cleanup don't show in the test report because the pass/fail assertions are already complete. But the problems it causes may show up in other ways.

提交回复
热议问题