FSharp.xUnit 1.2.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package FSharp.xUnit --version 1.2.3
                    
NuGet\Install-Package FSharp.xUnit -Version 1.2.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FSharp.xUnit" Version="1.2.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FSharp.xUnit" Version="1.2.3" />
                    
Directory.Packages.props
<PackageReference Include="FSharp.xUnit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FSharp.xUnit --version 1.2.3
                    
#r "nuget: FSharp.xUnit, 1.2.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FSharp.xUnit@1.2.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FSharp.xUnit&version=1.2.3
                    
Install as a Cake Addin
#tool nuget:?package=FSharp.xUnit&version=1.2.3
                    
Install as a Cake Tool

The class library extends xunit to assert equal.

  • It output data in F# style.

  • It's easier to customize the IEqualityComparer.

install

Install-Package FSharp.xUnit

GetStarted

使用系统默认的相等比较器:

open FSharp.xUnit

[<Fact>]
let ``My test`` () =
    Should.equal 1 1

相反的操作Should.notEqual

使用自定义的相等比较器,先配置比较器,newtonsoft.net是.net流行的json库,但是JProperty缺少结构化比较的方法,这个代码示例演示如何定义适配器:

let tryGetJProperty (ty: Type) =
    if ty = typeof<JProperty> then
        Some(fun (loop:Type -> IEqualityComparer) -> 
            let stringComparer = loop typeof<string>
            let jTokenEqualityComparer = JTokenEqualityComparer()
            {
                new IEqualityComparer with
                    member this.Equals(p1,p2) =
                        let p1 = unbox<JProperty> p1
                        let p2 = unbox<JProperty> p2
                        stringComparer.Equals(p1.Name, p2.Name) && jTokenEqualityComparer.Equals(p1.Value, p2.Value)
                    member this.GetHashCode(p) = 
                        let p = unbox<JProperty> p
                        hash [|stringComparer.GetHashCode p.Name; jTokenEqualityComparer.GetHashCode p.Value|]
            })
    else None
    
let tryGetJToken  (ty: Type) =
    if typeof<JToken>.IsAssignableFrom ty then
        Some(fun (loop:Type -> IEqualityComparer) -> 
            let genericComp = JTokenEqualityComparer()
            {
                new IEqualityComparer with
                    member this.Equals(p1,p2) = genericComp.Equals(unbox<JToken> p1,unbox<JToken> p2)
                    member this.GetHashCode(p) = 
                        genericComp.GetHashCode(unbox<JToken> p)
            })
    else None

let should = EqualConfig.``override``[ 
    tryGetJProperty
    tryGetJToken
    ]

注意派生类要放到基类的上面,否则派生类数据就会进到基类适配器,派生类适配器被旁路掉了。

获得了should,我们就可以进行自定义的测试了,测试的方法和上面的差不多:

[<Fact>]
member this.``translateFields``() =
    let y = [JProperty("b",JValue(null:obj));JProperty("a",JValue(0.0))]
    let z = [JProperty("b",JValue(null:obj));JProperty("a",JValue(0.0))]
    should.equal y z

相反的操作should.notEqual

ClassDataBase

open FSharp.xUnit

type MyArrays1() = 
    inherit ClassDataBase([ 
        [| 3; 4 |]; 
        [| 32; 42 |] 
    ])

type ClassDataBaseTest(output:ITestOutputHelper) =
    [<Theory>]
    [<ClassData(typeof<MyArrays1>)>]
    member _.v1 (a : int, b : int) = 
        Assert.NotEqual(a, b)
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.32 300 6/12/2025
1.2.31 115 2/1/2025
1.2.30 116 12/30/2024
1.2.29 102 12/30/2024
1.2.28 118 10/28/2024
1.2.27 154 5/9/2024
1.2.26 142 3/29/2024
1.2.25 133 3/6/2024
1.2.24 200 1/11/2024
1.2.23 160 1/9/2024
1.2.22 185 12/27/2023
1.2.21 198 11/19/2023
1.2.20 143 11/16/2023
1.2.19 145 11/13/2023
1.2.18 146 11/8/2023
1.2.17 139 11/8/2023
1.2.16 180 11/2/2023
1.2.15 152 11/1/2023
1.2.14 179 11/1/2023
1.2.13 144 10/27/2023
1.2.12 154 10/18/2023
1.2.11 181 9/23/2023
1.2.10 169 9/18/2023
1.2.9 231 7/22/2023
1.2.8 235 7/21/2023
1.2.7 320 3/13/2023
1.2.6 325 3/12/2023
1.2.5 323 3/8/2023
1.2.4 392 12/19/2022
1.2.3 540 5/30/2022
1.2.2 557 3/16/2022
1.2.1 441 10/26/2021
1.2.0 475 10/26/2021
1.1.0 460 3/20/2021
1.0.0 579 9/15/2020

ClassDataBase