可以用Mockall模拟单个方法吗? [英] Is that possible to mock a single method with Mockall?

查看:97
本文介绍了可以用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模拟单个方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆