unit-testing - 无法模拟 .... 必须启用分析器才能模拟、安排或执行指定的目标

标签 unit-testing telerik justmock

我在测试中有以下内容(我的第一次 JustMock 测试,我可能会添加)...

        var template = Mock.Create<MessageType>();
        Mock.Arrange(() => template.Subject)
            .Returns("This template has Zero tokens.");

        Mock.Arrange(() => template.Body)
            .Returns("This template has {{number}} of {{tokens}}.");

被 Mocked 的类看起来像这样......
public class MessageType : BaseBusinessEntity
{
    public string Body { get; set; }

    public int DigestsToBeIncludedOn { get; set; }

    public Guid MessageReference { get; set; }

    public int MessageTypeId { get; set; }

    public string Name { get; set; }

    public int PredefinedRecipients { get; set; }

    public string Subject { get; set; }
}

当我尝试运行测试时,我得到...

Error Message: Test method Genesis.Service.Implementation.Tests.DigestFixture.ShouldCorrectlyExtractTemplateTokens threw exception: Telerik.JustMock.Core.ElevatedMockingException: Cannot mock 'System.String get_Subject()'. The profiler must be enabled to mock, arrange or execute the specified target. Stacktrace: at Telerik.JustMock.Core.ProfilerInterceptor.ThrowElevatedMockingException(MemberInfo member) at Telerik.JustMock.Core.MocksRepository.CheckMethodInterceptorAvailable(IMatcher instanceMatcher, MethodBase method) at Telerik.JustMock.Core.MocksRepository.AddArrange(IMethodMock methodMock) at Telerik.JustMock.Core.MocksRepository.Arrange[TMethodMock](Expression expr, Func1 methodMockFactory) at Telerik.JustMock.Mock.<>c__DisplayClass81.b__6() at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func1 guardedAction) at Telerik.JustMock.Mock.Arrange[TResult](Expression1 expression) at Genesis.Service.Implementation.Tests.DigestFixture.ShouldCorrectlyExtractTemplateTokens() in c:\Genesis\Development\Genesis.Service.Implementation.Tests\DigestFixture.cs:line 46



谁能指出我做错了什么?

最佳答案

确保您已从菜单启用分析器。

在使用 Visual Studio 编写测试时,您会注意到 Telerik 菜单和其中的 JustMock 菜单项。在那里,您必须检查 JustMock 是否已启用(“Enable JustMock”应为灰色,请参见下面的示例)。

enter image description here

关于unit-testing - 无法模拟 .... 必须启用分析器才能模拟、安排或执行指定的目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30049752/

相关文章:

javascript - Kendo UI 多选框将 kendo.all.js 更新到最新版本

c# - 在 ASP.NET MVC 中模拟一个简单的服务总线

python - 检查字符串是否符合某种格式

java - Spock stub 在功能方法中不起作用

c# - 在网格上显示网格线

c# - 使用 JustMock 模拟 ConfigurationManager.AppSettings

c# - 如何使用 JustMock 模拟构造函数?

php - 使用 Eclipse SimpleTest 插件 - SimpleTest 不工作

ios - 从另一个类设置 UITextField 的文本

c# - DataTable 作为声明性数据源?