Jos*_*den 4 f# unit-testing xunit.net autofixture
我安装了Visual Studio 2012项目并安装了以下NuGet包:
鉴于以下设计的Logger类(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)
Run Code Online (Sandbox Code Playgroud)
以及单元测试:
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)
Run Code Online (Sandbox Code Playgroud)
在确保我显示所有测试并构建项目之后,测试资源管理器无法识别单元测试.项目构建正确,Build,General或Test输出日志中没有错误或警告.
如果我用Fact属性替换当前的Theory和AutoData属性,则会显示测试.
F#测试项目是否支持AutoFixture?任何人都可以复制这个并知道我做错了什么吗?
我认为这是Xunit.Extensions
使用Ploeh.Autofixture.Xunit
和测试运行器的冲突版本的问题.
如果您使用Xunit的跑步者运行测试,那么您应该看到一个例外,抱怨无法找到特定版本的Xunit.Extensions
.
您可以通过向测试项目添加绑定重定向来解决此问题app.config
.由于您正在使用NuGet,因此可以通过在测试项目的程序包管理器控制台中运行它来生成绑定重定向.
Add-BindingRedirect
Run Code Online (Sandbox Code Playgroud)
然后,您可以根据需要将生成的绑定重定向调整app.config
为更具体.
重建项目后,您应该看到测试出现在VS Test Explorer中.