NUnit测试覆盖扩展C#
我有以下方法,我无法更改NUnit测试覆盖扩展C#,c#,visual-studio,unit-testing,testing,extension-methods,C#,Visual Studio,Unit Testing,Testing,Extension Methods,我有以下方法,我无法更改 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); } 然后用这种方法测试它们
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
你知道吗
CS0111类型“Program”已使用相同的参数类型定义了名为“a”的成员
此错误告诉您编译器可以区分以下两种方法
static int A ( string var )
static int A ( this string var )
您可以通过更改其中一个方法的名称或参数,或者将其中一个方法移动到另一个类来解决此问题
CS0121以下方法或属性之间的调用不明确:'Program.A(string)'和'Program.A(string)'
此异常只是第一个异常的后续错误。当你调用
A(var)代码>编译器不知道您指的是哪种方法,因为两者都有相同的名称和相同的参数。我有以下无法更改的方法
您有这些方法的地方?在同一个类中?它们是由教师提供的。你认为将它们放在两个不同的类中可以解决问题吗?是的,因为错误文本意味着一个类不能包含两个具有相同名称和签名的方法。因此,您需要重命名其中一个或将它们放入不同的类中。