可以用Mockall模拟单个方法吗?

编程入门 行业动态 更新时间:2024-10-22 18:36:30
本文介绍了可以用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模拟单个方法吗?

本文发布于:2023-10-31 04:17:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544976.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以用   方法   Mockall

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!