1

我希望将TraceConsoleConsole Error输出写入通用 XML 报告文件(例如写入cad.UnitTests.xml)。默认情况下,此信息不是用 XML 编写的。

在此处输入图像描述

我该怎么做?nunit-console.exe有这样的参数:

/output=STR  File to receive test output (Short format: /out=STR)
/err=STR  File to receive test error output

但我需要将它放在同一个 XML 文件中。我在这两种情况下都需要它:nunit-console.exenunit.exe. 另外,我查看了 GUI NUnit 的设置,但一无所获。

我的 BAT 文件有这样的内容:

:: run_me.bat
:: © Andrey Bushman, 2015
ECHO OFF

CD /D %~dp0
SET file_name=cad.UnitTests

:: Run NUnit tests
call "%NUNIT%\nunit-console.exe" ^
  /out="%~dp0%file_name%_out.txt" ^
  /err="%~dp0%file_name%_err.txt" ^
  /trace=Verbose ^
  /noshadow ^
  /xml="%~dp0%file_name%.xml" ^
  "%~dp0%file_name%.dll"

:: Get the HTML report of the unit testing
call "%ReportUnit%\ReportUnit.exe" ^
  "%~dp0%file_name%.xml" ^
  "%~dp0%file_name%.html"

但即使我使用这样的命令:

call "%NUNIT%\nunit-console.exe" ^
  /out="%~dp0%file_name%_out.txt" ^
  /err="%~dp0%file_name%_err.txt" ^
  /noshadow ^
  /xml="%~dp0%file_name%.xml" ^
  "%~dp0%file_name%.dll"

那么两个文件中都没有Trace输出("%~dp0%file_name%_out.txt""%~dp0%file_name%_err.txt")。

我没有看到Trace 输出nunit-console.exe重定向的选项(类似于)。我看到了参数,但它有其他用途。/traceFile/trace

这对我来说是必要的,因为我使用结果 XML 通过ReportUnit.exe生成 HTML 。我想在 HTML 中查看详细信息。

我可以在单元测试的代码中将 Trace 输出保存到 TXT 文件中:

/* SetUpClass.cs
 * © Andrey Bushman, 2015
 */

namespace Bushman.CAD.UnitTests {
  using System;
  using System.IO;
  using System.Diagnostics;
  using NUnit.Framework;

  [SetUpFixture]
  public class SetUpClass {

    private TextWriterTraceListener listener = null;

    [SetUp]
    public void RunBeforeAnyTests() {
      Stream traceFile = File.Create("trace_out.txt");
      listener = new TextWriterTraceListener(traceFile);
      Trace.Listeners.Add(listener);
    }

    [TearDown]
    public void RunAfterAnyTests() {
      listener.Flush();
    }
  }
}

但是我仍然希望通过 NUnit 的“本机”方式在 XML 文件(由 NUnit 生成)中获取此信息。

4

0 回答 0