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 am trying to debug through my unit tests with visual studio but my breakpoints arent being hit - even though they are set correctly. I am definetly hitting the code - i have confirm by throw dummy exceptions and the debugger breaks into my source code at the right point.

Any ideas? I really need to be able to step through the code under test.

I have a small sample project to demonstrate this issue:

    public interface ISearch2
    {
        string GetString(int type);
    }

    public interface IProvision
    {
        ISearch2 Search { get; }
    }

    public abstract class BaseClass2
    {
        protected string GetString(IProvision p, int type)
        {  
            type++; // breakpoint set here not stopping debugger

            return p.Search.GetString(type);
        }
    }

    [TestClass]
    public class UnitTest2
    {
        [TestMethod]
        public void TestMethod1()
        {
            var mockInterface = Isolate.Fake.Instance<IProvision>();

            Isolate.WhenCalled(() => mockInterface.Search.GetString(1)).WithExactArguments().WillReturn("one");

            var mockBase = Isolate.Fake.Instance<BaseClass2>();
            Isolate.NonPublic.WhenCalled(mockBase, "GetString").CallOriginal();

            string s = Isolate.Invoke.Method(mockBase, "GetString", mockInterface, 0) as string;

            Isolate.Verify.WasCalledWithExactArguments(() => mockInterface.Search.GetString(1));

            Assert.IsNotNull(s);
            Assert.AreEqual(s, "one");
        }
    }
asked by solidstore (3.2k points)

3 Answers

0 votes
How are you running the test? Are you using ReSharper's runner, or that of MSTest?
answered by igal (5.7k points)
0 votes
I'm running the test with Visual Studio MSTest - Right click on test in Test View - Debug selection. I hit other breakpoints, e.g. the start of the unit test, just not the method that is being mocked
answered by solidstore (3.2k points)
0 votes
That's really odd, as I've tried with 3 test runners (just to make sure we didn't break anything in the latest version) - ReSharper, TestDriven.NET and Visual Studio, and I was able to set a breakpoint inside GetString.

Perhaps it would be best if I could have a look at it on your machine in an online session?
answered by igal (5.7k points)
...