question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FsUnit.Xunit : when using result type, on error, actual message is not showing the pretty printing but type info.

See original GitHub issue

Description

When the unit test “should equal” failed, an error message indicates the pretty printing for the Expected but only type info the the Actual one.

Repro steps

  1. Add the FsUnit.Xunit

  2. add a unit test with : Ok "hello" |> should equal (Ok "world")

Expected behavior

Expected result :

FsUnit.Xunit+MatchException: Exception of type 'FsUnit.Xunit+MatchException' was thrown.
Expected: Equals Ok "world"
Actual:  Equals Ok "hello"

Actual behavior

FsUnit.Xunit+MatchException: Exception of type 'FsUnit.Xunit+MatchException' was thrown.
Expected: Equals Ok "world"
Actual:   was Microsoft.FSharp.Core.FSharpResult`2[System.String,System.Object]
   at FsUnit.Xunit.Assert.That.Static[a](a actual, IMatcher`1 matcher) in /Users/sergey/github/FsUnit/src/FsUnit.Xunit/FsUnit.fs:line 19
   at FsUnitBench.AssertBug.result bug() in C:\gh\UnitTestingBenchmark\FsUnitBench\AssertBug.fs:line 9

Known workarounds

let private pretty x = sprintf "%A" x

let shouldBe (expected:'a) (actual:'a) = 
    if expected <> actual then 
        raise (Xunit.Sdk.EqualException(pretty expected, pretty actual))

Related information

  • Operating system
  • Branch
  • .NET Runtime, CoreCLR or Mono Version
  • Performance information, links to performance testing scripts

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
CaptnCodrcommented, Jun 26, 2020

Fixed with #155.

0reactions
CaptnCodrcommented, Jun 18, 2020

I opened a PR #155 which will fix the “ugly” message. Xunit and MsTest messages were affected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

F# XUnit test does not print output
I got output to appear without a failing test by using Console. ... WriteLine message type StackOverflow(output : ITestOutputHelper) = do ...
Read more >
Review: F# unit testing frameworks and libraries
A review of XUnit, FsUnit, Unquote, and Expecto as unit testing ... makes use of a cool F# language feature to give detailed...
Read more >
What is FsUnit?
FsUnit is a set of libraries that makes unit-testing with F# more enjoyable. It adds a special syntax to your favorite .NET testing...
Read more >
Idiomatic way to write proper F# (x)unit + fsunit tests?
I am writing some unit tests using XUnit in F# and I am wondering what is the most idiomatic way in the F#...
Read more >
List of unit testing frameworks
Name xUnit TAP Fixtures Group fixtures Generators License AceUnit Yes Yes BSD License AcuTest Yes Yes MIT API Sanity Checker Yes Yes (spectypes) Yes (spectypes) Yes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found