Edit: Below is the former question originally posted with the title
xunit show ITestOutputHelper output when run in the console
After investigation (see comments), the question is still very much relevant and in need of an answer but it seems that it should be addressed to the vstest
framework and around output sinks rather than xunit.
The specific question now is: When something is written to the dotnet vstest
output sink, how do I get it to display when running dotnet test
from the command line. Specifically I want to be able to set up a watcher with dotnet watch
to run tests continuously and I care more about output than results (I am using this less as a testing system and more as a development notebook). And I don't want to be limited to visual studio or vscode.
Original Question:
In my test class I have
[Fact]
public void Test() {
output.WriteLine("WHATEVER");
}
readonly ITestOutputHelper output;
public GroceryTests(ITestOutputHelper output) => this.output = output;
When I run this through the vscode in-editor integration I can see the output in the Output pane. When I run it via dotnet test
I do not. How do I get this output to show up via console?
The dotnet vstest command is superseded by dotnet test , which can now be used to run assemblies.
Luckily, dotnet test using xUnit V2 runs the tests inside of a project (or even inside a solution) in parallel by default. So at least the tests inside of a project will be started in parallel.
The dotnet vstest command runs the VSTest.Console command-line application to run automated unit tests. Run tests from the specified assemblies. Separate multiple test assembly names with spaces. Wildcards are supported. Runs the tests in blame mode. This option is helpful in isolating the problematic tests causing test host to crash.
Currently there is no way to output the test results from dotnet test. Our CI requires a file in order to determine if a job has failed or not plus it allows us to gather data from our builds. Would be useful for dotnet test to accept a output path for test results. @Greg15153 can you provide some more details?
Test published output with dotnet vstest. You can run tests on already published output by using the dotnet vstest command. This will work on xUnit, MSTest, and NUnit tests. Simply locate the DLL file that was part of your published output and run: Where <MyPublishedTests> is the name of your published test project.
The dotnet cli’s test command can be run on any msbuild project or solution, yet it fails when run on non-test projects and prints errors like: No test is available in [SomeApp].dll. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate and try again. Test Run Aborted.
Just to share what worked for me (I am no expert of vstest sink stuff, so probably can't answer deeper questions):
I have a simple test like this:
public class UnitTest1
{
private readonly ITestOutputHelper _output;
public UnitTest1(ITestOutputHelper output)
{
_output = output;
}
[Fact]
public void Test1()
{
_output.WriteLine("My message.");
}
}
So if I watch / run this test in console:
dotnet watch test --logger:"console;verbosity=detailed"
I see output like:
V XUnitTestProject1.UnitTest1.Test1 [5ms]
Standard Output Messages:
My message.
I am using .NET Core SDK 3.1.201.
@weichch's answer works for me even without any specific log sink usage.
The command
dotnet test -l "console;verbosity=detailed"
is showing me all the Console.WriteLine
s of my tests just fine. And doesn't clutter much.
Note that you can add --filter="Name=<MethodName>"
to the command to run tests with such name.
My tests all have attribute [NonParallelizable].
Using dotnet 5
The command is also mentioned in this answer at github.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With