我在 Visual Studio 2010 中遇到了单元测试问题。我粘贴了下面的简化代码。
[TestClass]
public class TestClassA<T>
{
[AssemblyInitialize()]
public static void Initialize(TestContext testContext) {}
}
[TestClass]
public class TestClassB : TestClassA<String>
{
[TestMethod]
public void TestMethod()
{
Assert.IsTrue(true);
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行时TestMethod(),出现以下异常:
Assembly Initialization method TestProject.TestClassA`1.Initialize threw exception. System.InvalidOperationException: System.InvalidOperationException: Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.. Aborting test execution.
at System.Reflection.RuntimeMethodInfo.ThrowNoInvokeException()
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, …Run Code Online (Sandbox Code Playgroud)