C# - NUnit控制台测试生成

时间:2017-09-05 09:47:46

标签: c# .net unit-testing nunit

目前我正在尝试使用NUnit在xml文件中获取测试结果。 我正在使用的以下命令是:

nunit3-console.exe --labels=All --out=TestResult.txt "--result=TestResult.xml;format=nunit3" "Acceptance Tests\AcceptanceTests.dll" --trace:Debug

我在输出窗口中收到的是: enter image description here

然后在生成的文件“TestResult.xml”中,我有测试运行元素

testcasecount="1" result="Failed" label="Error" total="1" passed="0" failed="1" inconclusive="0" skipped="0" asserts="0" engine-version="3.7.0.0" clr-version="4.0.30319.42000"

然后即将失败,例外情况为:

<failure>
  <message><![CDATA[An exception occurred in the driver while loading tests.]]></message>
  <stack-trace><![CDATA[
Server stack trace: 
at NUnit.Engine.Runners.DirectTestRunner.LoadDriver(IFrameworkDriver driver, String testFile, TestPackage subPackage)
at NUnit.Engine.Runners.DirectTestRunner.LoadPackage()
at NUnit.Engine.Runners.DirectTestRunner.EnsurePackageIsLoaded()
at NUnit.Engine.Runners.DirectTestRunner.RunTests(ITestEventListener listener, TestFilter filter)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: 
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at NUnit.Engine.ITestEngineRunner.Run(ITestEventListener listener, TestFilter filter)
at NUnit.Engine.Runners.ProcessRunner.RunTests(ITestEventListener listener, TestFilter filter)]]></stack-trace>
</failure>

这些是“InternalTrace”文件中的最后一个日志: enter image description here

我从“nunit-aget.log”获得的内容: enter image description here

项目中已安装的软件包包括:“NUnit”,“NUnit.Console”,“NUnit.ConsoleRunner”,“NUnit.Runners”,“NUnit3TestAdapter”

提前致谢

1 个答案:

答案 0 :(得分:1)

nunit-console目前无法运行.NET Core程序集。

您需要使用NUnit3TestAdapter,然后通过dotnet test运行。

有关详细信息,请参阅此处的文档:https://github.com/nunit/docs/wiki/.NET-Core-and-.NET-Standard

  

目前我正在尝试使用NUnit在xml文件中获取测试结果。

不幸的是,这还不适用于.NET Core。但是,有一个opn功能请求,您可以通过以下链接进行跟踪。欢迎提出请求!

https://github.com/nunit/nunit3-vs-adapter/issues/323