Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
FsUnit showing two identical expected values for F# types

The two tests below fail, of course. But why do the error messages show two identical expected values? Is there a way of only showing one?

myTest returns Expected: <B> or <B> But was: <A>

myTest2 returns Expected: <{ N = 2 }> or <{ N = 2 }> But was: <{ N = 1 }>

This works as expected (e.g. Expected: <B> But was: <A>) when using plain NUnit instead.

This gets pretty nasty when working with more complicated types, of course.

Tests.cs:

namespace Blah

open FsUnit
open NUnit.Framework

module Tests =

    type MyDU = A | B

    type MyRecord = { N: int }

    [<Test>]
    let myTest ()=
        A |> should equal B

    [<Test>]
    let myTest2 ()=
        { N = 1 } |> should equal { N = 2 }

Project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Tests.fs" />
  </ItemGroup>
  
  <ItemGroup>
    <PackageReference Update="FSharp.Core" Version="5.0.2" />
    <PackageReference Include="FsUnit" Version="4.2.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
  </ItemGroup>
  
</Project>
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

From looking at the source, it looks like this is the reason:

equal for 'structural equatable' items like records and unions use the NUnit constraint:

Is.EqualTo(x).Or.EqualTo(x).Using<'T>(Equality.Structural)

And this constraint will feed into the error message.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda