Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

Smart Runner Fails A Test That Passes In Resharper's Test Runner

+2 votes

Project type: Xamarin

Unit Test Framework: Nunit 3.6.1

TypeMock 8.6.0.10

I have my unit tests in a separate project. I am testing out a simple ViewModel with a single Property that is mocked. Not mocking the call and running in Resharper causes the error that I see in SmartRunner when the call is mocked. Very odd.

Here is my test class

 public readonly DependencyServiceStub _dependencyService = new DependencyServiceStub();

        [OneTimeSetUp]
        public void OneTimeSetup()
        {
            //Mock<Server> m = new Mock<Server>();
            //Isolate.NonPublic.StaticField<Server>("Instance").Value = new Server();

            var s = Isolate.Fake.AllInstances<Server>();
            Isolate.NonPublic.Property.WhenGetCalled(s, "NetworkCredential").WillReturn(new NetworkCredential());
            _dependencyService.Register<Server>(s);
        }

        [Test]
        public void the_vm_should_spinup()
        {
            var sut = new XmproLoginViewModel(_dependencyService);
            
            sut.ShouldNotBeNull();
        }

When I bebug the test in SmartRunner the Server class I am mocking is actually getting its ctor called. But not when debugging the test with Resharpers Test Runner. The full property and  chain that I am mocking for is:

Server.cs

public static Server Instance // => _server ?? (_server = new Server());
        {
            get
            {
                if (_server == null)
                    _server = new Server();
                return _server;
            }
        }

MyViewModel.cs 
if (Server.Instance.NetworkCredential != null)

I tried mocking the return of .Instance specifically, but TM complained there was not a Property called "Instance", but .NetworkCredentials was fine.

Thanks for any ideas.

 

asked Sep 14 by adamhill (140 points)

Hi Adam,

First of all, SmartRunner doesn't yet support Nunit 3.

Second, when you use:

var s = Isolate.Fake.AllInstances<Server>();

you are creating a handle for the server class and not an object. Have you tried using Fake.Instance?

What is the error that Isolator throws when the test fails?

Also if possible, send test logs to support at typemock.com

1 Answer

0 votes

SmartRunner doesn't yet support Nunit 3 which might be the root of the error message you're getting.

It on our roadmap.

answered Nov 7 by Raphy (2,440 points)
...