1

我正在使用 C#、Gallio 和 MbUnit 为我们的测试框架编写一个带有 UI 的测试运行器,看来我被卡住了。我设法通过从列表视图中选择以编程方式运行测试,并且还设法从文本框中的测试中获得结果,这一切都很好!但是,我需要一种方法来访问 TestLog.WriteLine (Gallio) 方法并将测试中的日志也显示到文本框中。这是运行测试的代码,也是从 TestLog 获取写入行的失败尝试:

MarkupStreamWriter streamWriter = TestLog.ConsoleOutput;
launcher.Logger = new MarkupStreamLogger(streamWriter);

launcher.TestProject.TestRunnerFactoryName = StandardTestRunnerFactoryNames.Local;
launcher.AddFilePattern(assembly.Location);
launcher.EchoResults = true;

var result = launcher.Run();

对此的任何意见将不胜感激!这是我的第一篇文章,如果不符合标准,请见谅:)

非常感谢!

4

1 回答 1

0

我使用以下代码(webConsole 是 ILogger 的一个实例):

                var logger = new FilteredLogger((ILogger)new RichConsoleLogger(webConsole), Verbosity.Normal);
                var setup = new RuntimeSetup();
                setup.AddPluginDirectory(@"C:\Program Files (x86)\Gallio\bin");
                if (!RuntimeAccessor.IsInitialized) {
                    RuntimeBootstrap.Initialize(setup, logger);
                }

                var progressMonitorProvider = new RichConsoleProgressMonitorProvider(webConsole);
                var launcher = new TestLauncher { Logger = logger, ProgressMonitorProvider = progressMonitorProvider, RuntimeSetup = setup, EchoResults = true };

                launcher.TestProject.TestRunnerFactoryName = StandardTestRunnerFactoryNames.Local; 
                launcher.AddFilePattern(@"\path\to\Tests.dll");
                var testLauncherResult = launcher.Run();
                webConsole.WriteLine(testLauncherResult.ResultSummary);
于 2014-08-13T06:55:21.283 回答