本文介绍了可以用Mockall模拟单个方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在模块范围内模拟常规的单个方法(而不是trait或struct方法),该方法将返回一个常量值,但我在文档中找不到任何示例.
I want to mock a regular single method in the module scope (not a trait or struct method), that will return a constant value, but I can't find any example in the docs.
推荐答案简短的回答是否",但是解决方法非常简单: 1)将您的单个free函数转换为结构的静态方法,并模拟该结构. 2)将您的单个free函数放入模块中,然后对模块进行模拟(每晚需要).
The short answer is no, but the workarounds are pretty easy: 1) Turn your single free function into a static method of a struct, and mock the struct. 2) Put your single free function into a module, and mock the module (requires nightly).
更多推荐
可以用Mockall模拟单个方法吗?
发布评论