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
I found that if I run tests that involve static method mocking at class level, the static method may not work.

Here's the code:
    public class MyVerification
    {
        public static bool WithinRange(int value, int min, int max)
        {
            return false;
        }
    }
    [TestFixture, ClearMocks]
    public class TypeMockTest
    {
        public  TypeMockTest()
        {
            
        }

        [SetUp]
        public void Init()
        {
            Isolate.WhenCalled(() => MyVerification.WithinRange(0, 0, 0)).WillReturn(true);
        }

        [Test, Isolated]
        public void Hello1()
        {
            
        }

        [Test, Isolated]
        public void Hello2()
        {
            Assert.IsTrue(MyVerification.WithinRange(0, 100, 1000));
        }
    }


Now, if I run Hello2 individually, using Testdriven.net, then the test will pass, this is the expected behavior.

But if I run the test on the whole class TypeMockTest by placing the mouse cursor at the TypeMockTest and click run test, the Hello2 test will fail because the MyVerification.WithinRange is not mocked.
________
volcano classic review
asked by nsoonhui (59.1k points)

1 Answer

0 votes
This bug seems like a variation of this issue:
https://www.typemock.com/community/viewt ... =4252#4252

This bug is fixed in the next version of Isolator.
answered by dhelper (11.9k points)
...