为什么在我的F#单元测试失败中缺少Unquote的输出?
我有一个用F#编写的单元测试,它使用Unquote库执行如下断言:为什么在我的F#单元测试失败中缺少Unquote的输出?,f#,f#-unquote,F#,F# Unquote,我有一个用F#编写的单元测试,它使用Unquote库执行如下断言: module Iccm open System open NUnit.Framework open Swensen.Unquote [<TestCase("0000000000000000000000000546314", "http://...er.aspx?FolderID=0000000000000000000000000546314")>] [<TestCase("00000000000000000
module Iccm
open System
open NUnit.Framework
open Swensen.Unquote
[<TestCase("0000000000000000000000000546314", "http://...er.aspx?FolderID=0000000000000000000000000546314")>]
[<TestCase("0000000000000000000000000535126", "http://...er.aspx?FolderID=0000000000000000000000000535126")>]
[<TestCase("0000000000000000000000000545845", "http://...er.aspx?FolderID=0000000000000000000000000545845")>]
[<TestCase("0000000000000000000000000364684", "http://...er.aspx?FolderID=0000000000000000000000000364684")>]
let ``callLink returns complete Uri with given eFolderId embedded``
eFolderId expectedUri =
test <@ Iccm.callLink eFolderId = expectedUri @>
我在命令行上尝试了NUnit,并在Visual Studio 2013中尝试了ReSharper,但两人似乎都不知道如何读取Unquote输出。有人知道为什么吗?我必须使用不同的测试运行程序才能使Unquote正常工作吗
更新:
另一个测试用例有一个失败,它很好地演示了Unquote输出:
[<TestCase(3s, "03/02/2015", 3150202)>]
let ``callPriority returns expected integer given a priority and date``
priority dateString expectedInteger =
let date = DateTime.Parse(dateString)
test <@ Iccm.callPriority priority date = expectedInteger @>
如果您阅读了错误消息,包括调用堆栈,您将看到异常是由NUnit测试运行程序引发的 永远不会执行测试主体,因为: “System.String”类型的对象无法转换为“System.Uri”类型
[TestCase]
属性中的值是string
值,但F#编译器似乎已将其中一个参数推断为Uri
实例
我猜是eFolderId
参数被推断为Uri
值,因为它被用作函数参数。不幸的是,我们不知道Iccm.callLink
函数的类型,所以这只是一个猜测
当一个或两个参数(eFolderId
或expectedUri
)静态键入为Uri
,而[TestCase]
值的运行时类型为字符串
值时,.NET运行时将尝试将字符串
转换为Uri
没有从string
到Uri
的隐式转换,这就是引发异常的原因
此时甚至不涉及Unquote。Hi Mark,是的,callLink函数返回Uri。通过测试使用表达式
test
。我删除了新的Uri只是为了强制一个错误,看看Unquote会告诉我什么。我想在失败变得如此严重之前,它必须更加微妙。
[<TestCase(3s, "03/02/2015", 3150202)>]
let ``callPriority returns expected integer given a priority and date``
priority dateString expectedInteger =
let date = DateTime.Parse(dateString)
test <@ Iccm.callPriority priority date = expectedInteger @>
Iccm.callPriority 3s 3/2/2015 12:00:00 AM = 3150202
3150302 = 3150202
false