如何导出 C# 单元测试的结果?

How can I export the results of a C# unit test?

有没有办法导出单元测试的结果?

当我 运行 NUnit 时,我能否得到正式的输出,说明哪些方法已经过测试,哪些方法失败了,哪些通过了?

您可以指定要输出到文件的测试结果:

Redirecting Text Output

Output created by the test, which is normally shown on the console, may be redirected to a file. The following command redirects standard output to the file TestResult.txt:

  nunit-console nunit.tests.dll /out:TestResult.txt

The following command redirects standard error output to the StdErr.txt file.

  nunit-console nunit.tests.dll /err:StdErr.txt

Note:This option only redirects output produced by the tests, together with selected NUnit output that is interspersed with the test output. It does not redirect all console output. If you want to redirect all output to a file, you should use command line redirection as supported by the shell you are using. This option exists for the purpose of separating test output from other output, such as the NUnit summary report.

来自NUnit documentation.

我刚刚通过完成以下步骤对我的一个测试程序集进行了测试:

  1. 已下载并安装最新版本的 NUnit
  2. 已将 'C:\Program Files (x86)\NUnit 2.6.4\bin' 添加到系统路径
  3. 导航到我的程序集在命令提示符中的位置
  4. 运行 nunit-console MyTests.dll /out:TestResult.txt

然后将结果写入同一目录中的 TestResult.txt。