How to diagnose “TestFixtureSetUp Failed”

前端 未结 11 1106
感动是毒
感动是毒 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:25

    I had this issue and it was caused by adding a private readonly Dictionary in the class, much the same way that you add a private const string.

    I tried to make the Dictionary a constant but you can't do that at compile time. I solved this by putting my Dictionary in a method that returns it.

    0 讨论(0)
  • 2021-02-06 22:27

    If you are using SpecFlow and C# in Visual Studio, look at the auto-generated <whatever>.feature.cs file after the test fails. On the public partial class <whatever>Feature line, you should see a symbol which when hovered over will show the reason that the NUnit fixture setup failed. In my case, it was that some of my BeforeFeature methods in my TestHooks class were not static. All BeforeTestRun, AfterTestRun, BeforeFeature, and AfterFeature methods need to be static.

    0 讨论(0)
  • 2021-02-06 22:31

    I'd check the Build Log first.

    If it's not obvious from that, you could try including Console.WriteLines in the tests - I'm not positive, but I think those are written to the Build Log. Alternately you could log to a file (even using log4net if you wanted to get fancy).

    If you have Visual Studio installed on the CI server, you could try running the build/tests from there. If it's a connectivity issue, that might resolve it.

    I've seen path issues, though, where relative paths to files were no longer correct or absolute paths were used. These are harder to debug, and might require logging the paths and then checking if they exist on the build server.

    0 讨论(0)
  • 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);
        }
     }
    
    0 讨论(0)
  • 2021-02-06 22:31

    I was troubled by this today. I did the following to get the actual error.

    (1) Write another test in a separate fixture which initializes an instance of the troubling test fixture, explicitly calls setup methods such as TestFixtureSetUp and SetUp if any, and then executes the target test method.

    (2) Add exception handling code for the new code above, and log / output the actual exception to somewhere.

    0 讨论(0)
提交回复
热议问题