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

i m getting a very strange behaviour and sure cannot explain it the closest i get to the problem is describe with the code below.

the expected behaviour is all test to pass. but they fail randomly .
using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using MbUnit.Core.Framework;
using MbUnit.Framework;
using MCH.Shared;
using TypeMock;

namespace MCH.Views.Test.Controllers
{
   [TestFixture]
   public class ClassNameTest
   {
      [SetUp]
      public void SetUp()
      {
//         Shared.Program.Session.BeginTransaction();
         MockManager.Init();
         Assembly.Load(Options.DalAssemblyPath);
      }

      [RowTest]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      public void MoveUpMoveDown(stri
asked by tolisss (28.8k points)

6 Answers

0 votes
Hi,

I don't really understand this test (What is [RowTest])
But you don't seem to use the TypeMock at all.
Do these tests work if you remove all TypeMock apis?
Do these tests work from nunit-console (I have seen TestDriven.NET have some strange behaviour)
answered by scott (32k points)
0 votes
I don't really understand this test (What is [RowTest])

rowTest is an mbUnit attribute so u can use arguments and execute a test multi times
But you don't seem to use the TypeMock at all.

what do u mean ? i initialize typeMock manager at setup, mock a treeview control ,set expectation,ask verification
Do these tests work if you remove all TypeMock apis?

yes the testing methods are only those that have any use of TypeMock . that happens through all my projects i just tried to give a simple example here
Do these tests work from nunit-console (I have seen TestDriven.NET have some strange behaviour)

cuase of the randomness of failure is difficult to test on nunit cause it doesn't have any attribute that could help.

i think that the problem is on TypeMock cause this failures occur only at methods that i use TypeMock
answered by tolisss (28.8k points)
0 votes
Hi,
I am trying to duplicate this, I will get back to you.
answered by scott (32k points)
0 votes
maybe u have to run the method many times in order to fail .
it does not fail every time
answered by tolisss (28.8k points)
0 votes
Hi i have discovered something and though i should post .
The problem i think is with the MockManager.Init method cause if u move in the above code the MockManager initialization line from the setup method to the setupFixture method all run as expected.

the following code runs as expected
using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using MbUnit.Core.Framework;
using MbUnit.Framework;
using MCH.Shared;
using TypeMock;

namespace MCH.Views.Test.Controllers
{
   [TestFixture]
   public class ClassNameTest
   {
      [TestFixtureSetUp]
      public void SetUpfixture()
      {
         MockManager.Init();
      }

      [SetUp]
      public void SetUp()
      {
//         Shared.Program.Session.BeginTransaction();
         
         Assembly.Load(Options.Instance.DalAssemblyPath);
      }

      [RowTest]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row("MoveDown", 0)]
      [Row("MoveUp", 1)]
      [Row(
answered by tolisss (28.8k points)
0 votes
Hi i have discovered something and though i should post .
The problem i think is with the MockManager.Init method cause if u move in the above code the MockManager initialization line from the setup method to the setupFixture method all run as expected.

Hi,
Thanks for sharing this.
I have been trying to setup this test scenario for quite some time now.

This problem can actually happen, when the method is JITed before MockManager.Init is called.
This can happen in a few scenarios including:
1. A previous test called the mocked method (ForeColor in our case) before MockManager.Init was ever called.
2. The mocked method is defined in the same class as the test
3. And some other cases too

Initializing the MockManager beforehand (in the [Setup]/[TestFixtureSetUp]) will solve these cases.

We will overcome these problems in future releases.
answered by scott (32k points)
...