In Visual Studio 2015 Community I have a sample ASP.NET 5 (vNext) project and a project with unit tests (xUnit.net). The version of DNX is 1.0.0-beta5. My goal is to add messages during the test run to the output pane. Here I took a way to do this, so my unit test code looks like this:
using Xunit; using Xunit.Abstractions; namespace UnitTests { public class UnitTest1 { ITestOutputHelper output; public UnitTest1(ITestOutputHelper output) { this.output = output; } [Fact] public void TestTestTest() { output.WriteLine("Test Message"); Assert.Equal(2, 2); } } }
Visual Studio Test Explorer discovers this test (and that's OK), but all I have in the Output pane (from Tests) is:
------ Run test started ------ ------ Test started: Project: UnitTests ------ Starting Microsoft.Framework.TestHost [C:\Users\*******\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta5\bin\dnx.exe --appbase "C:\Users\*******\Documents\Visual Studio 2015\Projects\MvcMovie\UnitTests" Microsoft.Framework.ApplicationHost --port 55837 Microsoft.Framework.TestHost --port 55893] Connected to Microsoft.Framework.TestHost Running tests in 'C:\Users\*******\Documents\Visual Studio 2015\Projects\MvcMovie\UnitTests\project.json' ========== Run test finished: 1 run (0:00:03,2267169) ==========
Also, there is not any link "Output" under the selected test run information, like here: (Only "Test passed... Elapsed time ...")
What should I do to make this ITestOutputHelper
work?
This solution works for me (Visual Studio 2017 and xUnit 2.2.0.3545).
Try adding the below configuration in the App.Config
file. (I don't know why. It was just needed. If it doesn't exist, just add a new one in your test project.)
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="xunit.diagnosticMessages" value="true"/> </appSettings> </configuration>
The output information will be written in Test
output as expected like below.
[xUnit.net 00:00:00.0853907] Starting: xxxAssemblyName (parallel test collections = on, max threads = 8) [xUnit.net 00:00:00.1689373] Example.xxxTestClassName [PASS] [xUnit.net 00:00:00.1697265] Output: [xUnit.net 00:00:00.1700698] xxxx your Test Message [xUnit.net 00:00:00.1797303] Finished: xxxAssemblyName
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