chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Hi,

We have a really simple example where the first test will fail if the second test runs as well. We use TestDriven.NET to run all the tests in one file, and the first test below will fail. If we run that particular test on its own, it passes.

This is a big problem to say the least!

   [TestFixture]
   [ClearMocks]
   public class TestItNow
   {
      [Test]
      [VerifyMocks]
      public void Test1()
      {
         ToolStripMenuItem item = new ToolStripMenuItem();
         item.Tag = "test";
         Assert.IsNotNull(item.Tag);
      }

      [Test]
      [VerifyMocks]
      public void Test2()
      {
         using (RecordExpectations recorder = RecorderManager.StartRecording())
         {
            ToolStripMenuItem menuItem = new ToolStripMenuItem();
            menuItem.Tag = "test";
         }

         ToolStripMenuItem item = new ToolStripMenuItem();
         item.Tag = "test";
      }
   }


Do you have any insight into this?

Cheers,

Rory
________
herbalaire vaporizer
asked by rorydriscoll (3.8k points)

1 Answer

0 votes
Hi Rory,

Most likely you are correct in your observation and there is a leakage of the mock.
The question is why?
I tried reproducing it here without any success so it might be something specific to the machine or the setup you are using.

:?: Which test is running first? I would say that test1 is executed before test2 so I wondering how test2 can affect test1 at all.

what I would do first, is look at the tracer and see what is happening.
Run the test in a debugger and stop at the end of test2 and look at the tracer. you should see that the creation of menuTagItem and the call to menuTagItem.Tag were mocked.

In any case ill drop you a mail cause i really would like to see the trace and logs.
answered by lior (13.2k points)
...