NUnit 运行 测试失败
NUnit running test(s) is failing
我的设置
CoreExtensions.Host.InitializeService();
package = new TestPackage(pathToTestDll);
builder = new TestSuiteBuilder();
suite = builder.Build(package);
和运行(请注意,测试是从套件中检索到的 NUnitTestMethods 的有效列表
foreach (NUnitTestMethod t in tests)
{
try
{
var res = t.RunTest();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
我得到这个作为异常堆栈:
at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target) at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at NUnit.Core.Reflect.InvokeMethod(MethodInfo method, Object fixture, Object[] args) at NUnit.Core.TestMethod.RunTestMethod() at NUnit.Core.TestMethod.RunTestCase(TestResult testResult)
注意 t.RunTest();不会失败,而是测试只是在 运行 处失败并且设置了 HasError 标志...
nunit.core 和 nunit.core.interfaces 在我的测试包和运行包中是相同的文件
您初始化了 CoreServices 但没有使用它们,因为您 运行 在非常低的级别进行测试。使用非一般用途的内部 类 总是有风险的。但是,如果您将它们零碎地放在一起而不是像 NUnit 本身那样使用它们,那将尤其危险。
如果您想 运行 以编程方式进行测试(这可能不是一个好主意,但它似乎是您想要做的)那么我建议您 select 并使用一个的 NUnit 运行 人员为您处理细节。 Select 来自 SimpleTestRUnner、RemoteTestRunner 或 TestDomain,具体取决于您希望测试的方式 运行 和位置。
TestDomain 将 运行 它们放在单独的 AppDomain 中,这通常是最简单和最安全的。 RemoteTestRunner 将 运行 它们放在当前的 AppDomain 中,重定向输出。 SimpleTestRunner 是最低级别的 运行ner(但仍然 way 比你正在做的更高级别)并且只是 运行s 它们所在的测试。请注意,您不能 运行 在同一 AppDomain(远程和简单)中进行测试,除非您已将所有测试文件、它们的引用和 NUnit 文件复制到同一目录中。
我的设置
CoreExtensions.Host.InitializeService();
package = new TestPackage(pathToTestDll);
builder = new TestSuiteBuilder();
suite = builder.Build(package);
和运行(请注意,测试是从套件中检索到的 NUnitTestMethods 的有效列表
foreach (NUnitTestMethod t in tests)
{
try
{
var res = t.RunTest();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
我得到这个作为异常堆栈:
at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target) at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at NUnit.Core.Reflect.InvokeMethod(MethodInfo method, Object fixture, Object[] args) at NUnit.Core.TestMethod.RunTestMethod() at NUnit.Core.TestMethod.RunTestCase(TestResult testResult)
注意 t.RunTest();不会失败,而是测试只是在 运行 处失败并且设置了 HasError 标志...
nunit.core 和 nunit.core.interfaces 在我的测试包和运行包中是相同的文件
您初始化了 CoreServices 但没有使用它们,因为您 运行 在非常低的级别进行测试。使用非一般用途的内部 类 总是有风险的。但是,如果您将它们零碎地放在一起而不是像 NUnit 本身那样使用它们,那将尤其危险。
如果您想 运行 以编程方式进行测试(这可能不是一个好主意,但它似乎是您想要做的)那么我建议您 select 并使用一个的 NUnit 运行 人员为您处理细节。 Select 来自 SimpleTestRUnner、RemoteTestRunner 或 TestDomain,具体取决于您希望测试的方式 运行 和位置。
TestDomain 将 运行 它们放在单独的 AppDomain 中,这通常是最简单和最安全的。 RemoteTestRunner 将 运行 它们放在当前的 AppDomain 中,重定向输出。 SimpleTestRunner 是最低级别的 运行ner(但仍然 way 比你正在做的更高级别)并且只是 运行s 它们所在的测试。请注意,您不能 运行 在同一 AppDomain(远程和简单)中进行测试,除非您已将所有测试文件、它们的引用和 NUnit 文件复制到同一目录中。