How can I reach and retrieve information from TestLog in Gallio into my test runner using C#?

121 Views Asked by At

I am writing a test runner with an UI for our testing framework using C#, Gallio and MbUnit and it appears that I am stuck. I managed to run tests programmatically by selecting from a list view and also managed to get the result from the test in a text box which is all good! However, I need a way to reach into the TestLog.WriteLine (Gallio) method and display the log from the test into the text box as well. Here is the code for running the tests and also unsuccessful try for getting the Write Lines from the 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();

Any input on this will be much appreciated! This is my first post so apologies if it doesn't meet the standards :)

Many thanks!

1

There are 1 best solutions below

0
ulu On

I use the following code (webConsole is an instance of 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);