F#UnitTest项目中的自动修复不在Test Explorer中显示单元测试 [英] AutoFixture in F# UnitTest Project Not Displaying Unit Tests in Test Explorer

查看:60
本文介绍了F#UnitTest项目中的自动修复不在Test Explorer中显示单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Visual Studio 2012项目并安装了以下NuGet软件包:

I have a Visual Studio 2012 Project and the following NuGet Packages installed:

  • 使用Moq进行自动模拟的自动修复
  • 使用xUnit.net数据理论进行自动修复
  • 自动修复
  • 起订量
  • xUnit.net:扩展
  • xUnit.net:跑步者
  • xUnit.net

给出以下人为设计的Logger类(Logger.fs):

Given the following contrived Logger class (Logger.fs):

namespace FUnit

type public ILoggerContext =
    abstract member LogPath :string

type public LoggerContext (logPath :string) =
    member val LogPath = logPath with get, set

    interface ILoggerContext with
        member this.LogPath = this.LogPath

type public Logger () =
    member this.Log (context: ILoggerContext) value =
        System.String.Format("Logged {0} to {1}.", value, context.LogPath)

以及以下单元测试:

namespace FUnit.Test

open FUnit

type public Math_Add() = 

    [<Xunit.Extensions.Theory>]
    [<Ploeh.AutoFixture.Xunit.AutoData>]
    member this.``Should Output Value And Path`` (path :string) =
        let context = new LoggerContext(path)
        let logger = new Logger()

        let expected = System.String.Format("Logged value to {0}.", path)
        let actual = logger.Log context "value"

        Xunit.Assert.Equal<string>(expected, actual)

在确保显示所有测试并构建项目后,测试资源管理器无法识别单元测试.该项目可以正确生成,并且在生成",常规"或测试"输出日志中没有错误或警告.

The Test Explorer does not recognize the unit test after ensuring I'm showing all tests and building the project. The project builds correctly with no errors or warnings in the Build, General, or Test output logs.

如果我用Fact属性替换当前的Theory和AutoData属性,则会显示测试.

If I replace the current Theory and AutoData attributes with an Fact attribute, the test shows up.

F#测试项目中是否支持AutoFixture?任何人都可以复制并知道我在做什么错吗?

Is AutoFixture supported in F# test projects? Can anyone else replicate this and know what I'm doing wrong?

推荐答案

我认为这是与 Ploeh.Autofixture.Xunit 使用的 Xunit.Extensions 版本冲突的问题.>和测试跑步者.

I think this is an issue with conflicting versions of Xunit.Extensions used by Ploeh.Autofixture.Xunit and the test runner.

如果使用Xunit的运行程序运行测试,则应该看到一个异常,抱怨无法找到 Xunit.Extensions 的特定版本.

If you run the tests using Xunit's runners then you should see an exception complaining about not being able to find a specific version of Xunit.Extensions.

您可以通过将绑定重定向添加到测试项目 app.config 中来解决此问题.由于您使用的是NuGet,因此可以通过在Package Manager控制台中为测试项目运行它来生成绑定重定向.

You can fix this by adding binding redirects to your test projects app.config. Since you're using NuGet you can have it generate the binding redirects by running this in the Package Manager Console for your test project.

Add-BindingRedirect

然后,您可以根据需要在 app.config 中调整生成的绑定重定向,使其更具体.

You can then tweak the generated binding redirects in app.config to be more specific if you want.

一旦重建项目,您应该会看到测试出现在VS Test Explorer中.

Once you rebuild the project you should see the test appear in VS Test Explorer.

这篇关于F#UnitTest项目中的自动修复不在Test Explorer中显示单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆