(MaxTimeDecorator) Instance fields initialized by TestFixtureSetUp are null when test runs

"Joseph A. Davidson" <[email protected]>
Newsgroups gmane.comp.windows.dotnet.nunit.user
Message-ID <[email protected]>
See attached file.
Using NUnit 2.4.2 on XP SP2/.NET 2.0, the null checks for "list" fail in both tests when the MaxTimeDecorator add-in is installed.

When using a derived TestCase to run tests (like the MaxTimeDecorator sample), it seems like it creates a new instance of the class for each test, so the non-static fields are set back to null.

We made an add-in very similar to the MaxTimeDecorator sample that runs a test and does some custom handling after the test has run. The ITestDecorator.Decorate() method is setup to create a new TestCase-derived object for every method with TestAttribute.

We have hundreds of existing test fixtures that follow a pattern of initializing fields in the TestFixtureSetUp and using those objects in each test. This issue can be resolved by making these objects static, but I'd like to solve this without modifying the tests themselves.

Thanks,

Joe

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

_______________________________________________
Nunit-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nunit-users
MaxTimeDecoratorTests.cs (text/plain, 1.2 KB)
// ****************************************************************
// Copyright 2007, Charlie Poole
// This is free software licensed under the NUnit license. You may
// obtain a copy of the license at http://nunit.org/?p=license&r=2.4
// ****************************************************************

using System;
using NUnit.Framework;
using NUnit.Framework.Extensions;
using System.Collections;

namespace Tests
{
    [TestFixture]
    public class MaxTimeDecoratorTests
    {
        IList list = null;
        static IList staticList = null;

        [TestFixtureSetUp]
        public void FixtureSetup()
        {
            list = new ArrayList();
            staticList = new ArrayList();
        }

        [Test, MaxTime( 1000 )]
        public void MaxTimeNotExceeded() 
        {
            Assert.IsNotNull( staticList, "staticList should not be null" );
            Assert.IsNotNull( list, "list should not be null" );
        }

        [Test, MaxTime(1000)]
        public void AnotherTest()
        {
            Assert.IsNotNull( staticList, "staticList should not be null" );
            Assert.IsNotNull( list, "list should not be null" );
        }
    }
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.