gpt4 book ai didi

c# - 实现接口(interface)的具体类是否应该有额外的公共(public)方法进行测试?

转载 作者:行者123 更新时间:2023-11-30 15:51:14 25 4
gpt4 key购买 nike

<分区>

在具体类上实现接口(interface)时,公开额外的公共(public)方法以帮助促进单元测试是否合适?

例如,假设我有以下具体类:

public class MyClass : IMyInterface
{
public int InterfaceMethod(ComplexObject complexObject)
{
return NonInterfaceMethodOne(complexObject)
+ NonInterfaceMethodTwo(complexObject);
}

public int NonInterfaceMethodOne(ComplexObject complexObject)
{
//Do complex logic that needs to be unit tested
}
public int NonInterfaceMethodTwo(ComplexObject complexObject)
{
//Do more complex logic that needs to be unit tested
}
}

如果我这样写我的类,我可以对两种非接口(interface)方法进行单元测试,但我觉得这种模式不正确。有没有更好的办法?

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