xUnit showing truncated Expected and Actual in Test Explorer

2.4k views Asked by At

I am using xUnit with Visual Studio Test Explorer and when there's an error in Assert.Equal(), I am getting a truncated version of Actual and Expected.

For example,

Xunit.Sdk.EqualException
Assert.Equal() Failure
Expected: List<Result> 
[Result { 
Status = StatusEnumValue1, 
Message = "The request or response type contains a special ty"..., 
Path = "1234" }]
Actual:   WhereListIterator<Result> 
[Result { 
Status = StatusEnumValue1, 
Message = "The request or response type contains a special ty"..., 
Path = "1234" }]

This test fails because the Messages are different, but given that the Messages are truncated, I cannot see the part where they actually are different from the Test Explorer. Even when I copy it out, it's still truncated.

Is this a known shortcoming of xUnit? I can keep debugging the test or use WriteLine to compare the Messages but I am surprised the xUnit framework does not have a way to allow full response to be shown. I also tried the Resharper test explorer, and that does not solve the problem.

3

There are 3 answers

0
KangarooWest On BEST ANSWER

It turns out this is an xUnit issue.

ovation22 points own below the exact location of the code that controls this hard limit on number of characters.

I have bypassed this issue by using FluentAssertions library instead. The error from xUnit used with FluentAssertions does not truncate any error message.

4
ovation22 On

This appears to be a limitation of Visual Studio. This looks to be resolved with Visual Studio 2017.3.

https://developercommunity.visualstudio.com/content/problem/30703/test-explorer-result-text-truncated.html

0
Justin B. On

There's a very cumbersome way to view the full information using only xUnit and Visual Studio. I'm not familiar with FluentAssertions, but it does sound like an easier way.

Here's the steps to find the untruncated information with just Visual Studio and xUnit:

  1. Right click on the failing test (Ctrl+r, Ctrl+t also works)
  2. A small popup with the Exception will show in Visual Studio
  3. Click "View Details"
  4. This will popup another screen called QuickWatch, that has all of the related information in full untruncated form.