gpt4 book ai didi

f# - FsCheck.xUnit : testing types from another assembly

转载 作者:行者123 更新时间:2023-12-01 06:50:30 24 4
gpt4 key购买 nike

我正在尝试使用 FsCheck 和 xUnit 进行第一次测试。我有以下设置:

  • 具有单个文件的 F# 类库

    namespace Lib
    type ABC = A | B | C
  • 一个名为 Tests 的项目,它引用了具有单个文件的 FsCheck.xUnit NuGet 包:

    module LibTests    
    open FsCheck.Xunit
    open Lib
    [<Property>]
    let ``ABC is always A`` v =
    v = A

当我运行项目(使用 VS 或控制台运行器)时,出现以下错误:

System.Exception : The type Lib.ABC is not handled automatically by FsCheck. 
Consider using another type or writing and registering a generator for it

如果我将我的类型移至测试程序集,一切正常(测试失败)。如何测试外部类型?

最佳答案

它似乎与一个已知问题有关 described on FsCheck GitHub .

基本上,FsCheck NuGet 包依赖于旧版本的 FSharp.Core 库。旧版本被引用,导致测试代码与被测系统不兼容。

解决问题:

  1. 安装 FsCheck NuGet 包后,转到测试项目引用并删除对旧版本 FSharp.Core(在我的例子中是 4.3.1.0)的引用。

  2. 点击“Add reference”再次添加它,转到 Assemblies -> Extensions 并添加与您其他项目中使用的相同版本的 FSharpCore,在我的例子中是 4.4.0.0 .

  3. App.config 文件添加到您的测试项目,其中包含以下内容:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
    <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="4.3.1.0" newVersion="4.4.0.0" />
    </dependentAssembly>
    </assemblyBinding>
    </runtime>
    </configuration>

关于f# - FsCheck.xUnit : testing types from another assembly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34844370/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com