将StoryQ(BDD框架)与xUnit一起使用时,控制台输出不起作用。这是解决方法
public class UnitTest
{
private readonly ITestOutputHelper _output;
public UnitTest(ITestOutputHelper output)
{
_output = output;
}
[Fact]
public void Fact()
{
var consoleOut = new StringWriter();
Console.SetOut(consoleOut);
try
{
new Story("Some story")
.InOrderTo("gain a shared understanding")
.AsA("agile team")
.IWant("document the behaviors for discussion")
.WithScenario("some scenario")
.Given(DoSomething)
.When(DoSomething)
.Then(DoSomething)
.Execute();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
finally
{
consoleOut.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList()
.ForEach(l => _output.WriteLine(l));
}
}
private void DoSomething()
{
//whatever
}
}