【发布时间】:2014-03-18 11:46:21
【问题描述】:
假设我们有一个类
type ThisClassIsComplicated () =
let calculateSomething a b =
a + b
在这种情况下,calculateSomething 是微不足道的,但如果它会更复杂,那么验证那里所做的计算是否正确可能是有意义的。
使用unit testing framework 来测试私有方法可能是有意义的。
我的问题:如何在 F# 中对私有方法进行单元测试?
一些随意的想法:
选择的答案here,建议使用InternalsVisibleTo attribute,无论如何它只适用于internalmethods。
如果有的话,特定于 F# 的路由是什么?这在 F# 设计中更好吗?
let calculateSomething a b = a + b
type ThisClassIsComplicated () =
member this.Calculate a b = calculateSomething a b
也许calculateSomething 的范围甚至可以通过nested module 来缩小。
【问题讨论】:
-
“使用单元测试框架来测试私有方法可能是有意义的。”不,它没有:stackoverflow.com/a/1093481/126014
标签: unit-testing f# private-members