【发布时间】:2017-11-30 19:36:36
【问题描述】:
我有以下方法我无法改变
static int A ( string var )
static int A ( this string var )
由于它们被定义为静态的,为了测试它们,我想创建像这样调用它们的公共方法
public static int ATest ( string var )
{
return A(var);
}
public static int ATestThis ( this string var )
{
return A(var);
}
然后以这种方式测试它们
namespace test.NUnit
{
[TestFixture]
public class myFirstTest
{
[Test]
public void TestOnA() {
Assert.... // with ATest and ATestThis
}
}
}
但是我得到了这两个错误
Type 'Program' already defines a member called A with the same parameter types
The call is ambiguous between the following methods or properties
你有什么想法吗?
【问题讨论】:
-
I have the following methods that I cannot change你在哪里?同班? -
老师提供的
-
你认为把它们放在两个不同的类中可以解决问题吗?
-
是的,因为错误文本意味着一个类不能包含两个具有相同名称和签名的方法。因此,您需要重命名其中一个或将它们放到不同的类中。
标签: c# visual-studio unit-testing testing extension-methods