[英]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>
myTest
返回Expected: <B> or <B> But was: <A>
myTest2
returns Expected: <{ N = 2 }> or <{ N = 2 }> But was: <{ N = 1 }>
myTest2
返回Expected: <{ N = 2 }> or <{ N = 2 }> But was: <{ N = 1 }>
This works as expected (eg Expected: <B> But was: <A>
) when using plain NUnit instead.这在使用普通 NUnit 时按预期工作(例如
Expected: <B> But was: <A>
)。
This gets pretty nasty when working with more complicated types, of course.当然,当处理更复杂的类型时,这会变得非常糟糕。
Tests.cs:测试.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>
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: equal
记录和联合等“结构可平等”项目使用 NUnit 约束:
Is.EqualTo(x).Or.EqualTo(x).Using<'T>(Equality.Structural)
And this constraint will feed into the error message.并且此约束将输入到错误消息中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.