gpt4 book ai didi

c# - 如何为具有 protected 方法的内部类型类编写 nunit 测试用例?

转载 作者:行者123 更新时间:2023-11-30 19:39:55 25 4
gpt4 key购买 nike

如何为具有 protected 方法的内部类型类编写 Nunit 测试用例。我应该为此使用继承吗?以下是我正在尝试为其编写测试用例的类(class):-

internal class CSGetBuyerAbuseReportsRequestTanslator
{
protected override CSGetBuyerAbuseReportsRequestType BusinessToService(IEntityTranslatorService service, BuyerAbuseRequest value)
{
//code
}
}

请建议我如何为这个类编写测试用例?

最佳答案

我假设您有一个单独的程序集,其中包含单元测试。如果是这样,您可以向被测试程序集的 AssemblyInfo.cs 文件中添加一行,类似于以下内容(用单元测试程序集的名称替换 AssemblyB):

[程序集:InternalsVisibleTo("AssemblyB")]

这将允许您的单元测试程序集访问您正在测试的程序集中包含的 internal 类。参见 this MSDN post ,其中声明了以下关于 InternalsVisibleTo 的使用:

This is especially convenient...when test code runs in a separate assembly but requires access to members in the assembly being tested that are marked as Friend (Visual Basic) or internal (C#).

关于c# - 如何为具有 protected 方法的内部类型类编写 nunit 测试用例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25680365/

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