gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 00:22:20 32 4
gpt4 key购买 nike

我在测试中有以下内容(我的第一次 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__DisplayClass8
1.b__6() at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func1
guardedAction) at Telerik.JustMock.Mock.Arrange[TResult](Expression
1 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com