How to diagnose “TestFixtureSetUp Failed”

前端 未结 11 1124
感动是毒
感动是毒 2021-02-06 21:46

We use TeamCity as our CI server, and I\'ve just started seeing \"TestFixtureSetUp Failed\" in the test failure window.

Any idea how I go about debugging th

11条回答
  •  南笙
    南笙 (楼主)
    2021-02-06 22:31

    I ran into this today when creating some integration tests that have long running setup that I don't want to duplicate. I ended up wrapping all the test fixture setup logic in a try/catch. I then add a SetUp method whose sole purpose is to see if a failure occurred during fixture setup and provide better logging.

    Exception testFixtureSetupException = null;
    
    [TestFixtureSetUp]
    public void FixtureSetup()
    {
        try
        {
            // DoTestFixtureSetup
        }
        catch (Exception ex)
        {
            testFixtureSetupException = ex;
        }
    }
    
    [SetUp]
    // NUnit doesn't support very useful logging of failures from a TestFixtureSetUp method. We'll do the logging here.
    public void CheckForTestFixturefailure()
    {         
        if (testFixtureSetupException != null)
        {
            string msg = string.Format("There was a failure during test fixture setup, resulting in a {1} exception. You should check the state of the storage accounts in Azure before re-running the RenewStorageAccountE2ETests. {0}Exception Message: {3}{0}Stack Trace:{4}",
                Environment.NewLine, testFixtureSetupException.GetType(), accountNamePrefix, testFixtureSetupException.Message, testFixtureSetupException.StackTrace);
            Assert.Fail(msg);
        }
     }
    

提交回复
热议问题