如何防止在基于模型的测试中收缩?
How do I prevent shrinking in Model-based testing?
以下是 FsCheck 中基于模型的测试示例:
let spec =
let inc = { new Command<Counter, int>() with
override __.RunActual counter = counter.Inc(); counter
override __.RunModel m = m + 1
override __.Post(counter, m) = counter.Get = m |@ sprintf "model: %i <> %A" m counter
override __.ToString() = "inc" }
let dec = { new Command<Counter, int>() with
override __.RunActual counter = counter.Dec(); counter
override __.RunModel m = m - 1
override __.Post(counter, m) = counter.Get = m |@ sprintf "model: %i <> %A" m counter
override __.ToString() = "dec" }
{ new ICommandGenerator<Counter,int> with
member __.InitialActual = Counter()
member __.InitialModel = 0
member __.Next model = Gen.elements [inc;dec] }
如何禁用此测试的命令收缩?
如果你想阻止 FsCheck 缩减使用的命令数量(见我上面的问题),你可以将规范转换为 属性 禁用缩减:
let property =
let generator = Command.generate spec
let shrinker _ = Seq.empty // disable
Command.toPropertyWith spec generator shrinker
Check.Quick(property)
这允许 FsCheck 生成比必要的更长的命令序列。例如。 [inc; inc; dec; inc; inc; dec; dec; dec]
.
以下是 FsCheck 中基于模型的测试示例:
let spec =
let inc = { new Command<Counter, int>() with
override __.RunActual counter = counter.Inc(); counter
override __.RunModel m = m + 1
override __.Post(counter, m) = counter.Get = m |@ sprintf "model: %i <> %A" m counter
override __.ToString() = "inc" }
let dec = { new Command<Counter, int>() with
override __.RunActual counter = counter.Dec(); counter
override __.RunModel m = m - 1
override __.Post(counter, m) = counter.Get = m |@ sprintf "model: %i <> %A" m counter
override __.ToString() = "dec" }
{ new ICommandGenerator<Counter,int> with
member __.InitialActual = Counter()
member __.InitialModel = 0
member __.Next model = Gen.elements [inc;dec] }
如何禁用此测试的命令收缩?
如果你想阻止 FsCheck 缩减使用的命令数量(见我上面的问题),你可以将规范转换为 属性 禁用缩减:
let property =
let generator = Command.generate spec
let shrinker _ = Seq.empty // disable
Command.toPropertyWith spec generator shrinker
Check.Quick(property)
这允许 FsCheck 生成比必要的更长的命令序列。例如。 [inc; inc; dec; inc; inc; dec; dec; dec]
.