public class test2InAnotherProject
{
private readonly ITestOutputHelper output;
public test2InAnotherProject(ITestOutputHelper output)
{
this.output = output;
}
int Diff(int a, int b)
{
return (a - b);
}
int Div(int a, int b)
{
return (b / a);
}
[Fact]
public void Test2()
{
int a = 2, b = 4;
output.WriteLine("Test1: Project 2 in old library");
int c = Diff(a, b);
Assert.Equal(c, (a - b));
output.WriteLine("Test1: Asssert done Project 2 in old library");
}
[Fact]
public void Test3()
{
int a = 2, b = 4;
output.WriteLine("Test2: Project 2 in old library");
int c = Div(a, b);
Assert.Equal(c, (float)((b / a)));
output.WriteLine("Test2: Assert done Project 2 in old library");
}
}
尝试使用命令通过命令提示符运行测试时打印这些行
dotnet test --no-build
尝试Console.Writeline
,之后我尝试用Output.WriteLine
。即使我从Visual Studio运行也无法在输出窗口中打印这些行。
请注意,您可以使用ITestOutputHelper,它应该写输出。
请refer this documentation了解更多详情。
public class MyTestClass
{
private readonly ITestOutputHelper output;
public MyTestClass(ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void MyTest()
{
var temp = "my class!";
output.WriteLine("This is output from {0}", temp);
}
}