Sunday, March 15, 2009

How to get the console output working with NBehave 0.4 and the ReSharper Testrunner

When working with the latest build of NBehave 0.4 you may notice that there is no output written to the ReSharper Testrunner Output anymore.

Here is how I did workaround the problem. I derived the specs from the following class and every thing was fine again:
public class SpecBaseWithConsoleOutput: SpecBase
{
private EventHandler<EventArgs<MessageEventData>> addedHandler;
private EventHandler<EventArgs<Scenario>> scenarioCreatedHandler;
private EventHandler<EventArgs<Story>> storyCreatedHandler;
public override void MainSetup()
{
base.MainSetup();
addedHandler = (o, a) => Console.WriteLine(a.EventData.Message);
scenarioCreatedHandler = (o, a) => Console.WriteLine(a.EventData.Title);
storyCreatedHandler = (o, a) => Console.WriteLine(a.EventData.Title);
Story.MessageAdded += addedHandler;
Story.ScenarioCreated += scenarioCreatedHandler;
Story.StoryCreated += storyCreatedHandler;
}
public override void MainTeardown()
{
Story.MessageAdded -= addedHandler;
Story.ScenarioCreated -= scenarioCreatedHandler;
Story.StoryCreated -= storyCreatedHandler;
base.MainTeardown();
}
}