1

我正在与 Rider 一起使用 Linux vm 来修复移植到这个新环境(以前是带有 VS 的 Windows)中的单元测试。我在调试时遇到问题。无论在测试中哪里有一个模拟实例,如果我在主题代码中引用被模拟的东西的任何地方放置一个断点,在调试模式下运行测试会导致测试中止而没有堆栈跟踪。

骑手报告:

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

这是我正在编写的测试文件中的完整代码,只是为了隔离问题。
评论中的重要说明

using NUnit.Framework;
using Moq;

namespace UnitTests
{
    [TestFixture]
    public class TestDebugging
    {
        private Mock<MockableThing> _testMock;

        [SetUp]
        public void SetUp()
        {
            _testMock = new Mock<MockableThing>();
        }

        [Test]
        public void TestMe()
        {  
            _testMock.Setup(m => m.GetSomething()).Returns("mock thingy.");

            var sut = new Subject(_testMock.Object);   

            //breakpoint here will work in debug mode, but stepping 
            //into the call causes the test to abort.             
            var something = sut.SaySomething();
            Assert.IsTrue(true);
        }

        public class Subject
        {
            private MockableThing _thing;

            public Subject(MockableThing thing)
            {
                //Placing a breakpoint here and running in debug mode
                //causes the test to abort.
                _thing = thing;
            }

            public string SaySomething()
            {
                return _thing?.GetSomething();
            }
        }

        public class MockableThing
        {
            public string Id { get; set; }
            public virtual string GetSomething()
            {
                return "this shouldn't be returned because it is mocked.";
            }
        }
    }
}

任何人都可以提供可能导致完全解决此问题的见解吗?

4

0 回答 0