小编Ana*_*sia的帖子

如何用f#用模拟编写测试

我想用模拟对象编写F#单元测试.我正在使用NUnit.但不幸的是我找不到任何例子.

以下是测试代码的示例:

type ICustomer = interface
    abstract Id: int with get
    abstract Name: string with get
    abstract CalculateBalanceWithDiscount: decimal -> decimal
end

type Customer = class
    val id: int
    val name: string
    val balance: decimal
    new(id, name, balance) = 
        {id = id; name = name; balance = balance}
    interface ICustomer with
        member this.Id 
            with get () = this.id
        member this.Name
            with get () = this.name
        member this.CalculateBalanceWithDiscount discount =
            this.balance - (discount * this.balance)
    end
end
Run Code Online (Sandbox Code Playgroud)

f# unit-testing mocking

4
推荐指数
2
解决办法
1393
查看次数

标签 统计

f# ×1

mocking ×1

unit-testing ×1