Rhino Mock

2023-05-16

  1. mock interfaces, delegates and classes, including those with parameterized constructors.
  2. set expectations on the called methods by using strongly typed mocks instead of strings.
  3. lends itself easily to refactoring & leaning on the compiler.
  4. allows a wide range of expectations to be set on a mock object or several mock objects.
  5. Attention: Rhino Mocks can only mock interfaces, delegates and virtual methods of classes! (Although it is possible to get work around existing code and easily apply Rhino Mocks, see Example of testing an abstract class)
  6. Rhino Mocks now supports "Recursive mocking" (as of revision 1683). Special guidance (see here) should be followed when using this functionality, however.

使用的规则。

All I need to do is abide by three rules:

  1. Use the static MockRepository.GenerateMock method.  Don’t use an instance of a MockRepository, and don’t use the GenerateStub method.
  2. If the mocked instance method returns a value, use the Stub method to set up a result for that value.  This is an indirect input.
  3. If the mocked instance method does not return a value (void), use the AssertWasCalled/AssertWasNotCalled methods.  This is an indirect output.

一。主要思想。

1。 Record/Replay 方式,在record mode set up expectation . in replay mode verify .(列出预期的方法,调用,验证是否被调用,调用顺序。)

2.   Arrange/Act/Assert方式,(类似于传统的nunit方法,准备数据,执行,假设结果)

 

Rhino Mocks currently support the creation of the following types of mock objects.

  • Mock Objects - Strict replay semantics. Created by calling StrictMock()
  • Dynamic Mock - Loose replay semantics. Created by calling DynamicMock()
  • Partial Mock - Mock only requested methods. Created by calling PartialMock()

Strict replay semantics: Only the methods that were explicitly recorded are accepted as valid. This means that any call that is not expected would cause an exception and fail the test. All the expected methods must be called if the object is to pass verification.

严谨重播语义:只有显示记录的方法才是有效的,对任何未预期的方法进行调用都会导致异常。所有预期的方法都必须被调用,对象才能通过验证。


Loose replay semantics: All method calls during the replay state are accepted. If there is no special handling setup for a given method, a null or zero is returned. All of the expected methods must be called for the object to pass verification.

松散重播语义:所有的方法都可以调用,未预期的调用会返回0 or null 所有的预期方法必须被调用,对象才能通过验证。


Mocking only requested methods: This is available for classes only. It basically means that any non abstract method call will use the original method (no mocking) instead of relying on Rhino Mocks' expectations. You can selectively decide which methods should be mocked.

仅模拟请求的方法:只适用于类。

DynamicMock 用于验证部分方法,StrictMock用于整个接口验证。PartialMock 可以用于测试类,抽象类的部分方法,尤求是模板方法的测试。

DynamicMock和StrictMock的区别仅限于上面提到的,而实际使用时,效应各个方法入 record,之类时 是一样的。

转载于:https://www.cnblogs.com/zhangchenliang/p/4076703.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Rhino Mock 的相关文章

  • something about Google Mock

    下载 xff1a http code google com p googlemock downloads list 安装 xff1a 将下载的压缩包解压出来 xff0c 到解压目录下执行 xff1a configure 然后执行 xff1a
  • dubbo之mock模拟

    1 写在前面 考虑这样的场景 当服务提供者还没有开发完毕或者是因为某些原因无法启动时 会导致服务消费者方的停滞 此时为了能够正常的开发测试 可以使用mock功能 在服务消费者端提供一个服务接口的mock实现类 来模拟调用服务提供者正常获取结
  • 如何mock系统调用

    背景 Linux下开发存储系统 网络库的时候会用到一系列Linux的系统调用 每一个系统调用都有一些出错的场景 有些场景很极端 比如内存使用达到上限 磁盘写满等 如果对其进行测试的话 很难去构造这样的一个场景 这个时候集成测试就显得力不存心
  • yapi的安装

    Yapi的安装 Yapi是一款不错的接口管理软件 我主要用它来进行接口Mock Yapi安装所需环境 Node js 7 6 Mongodb 2 6 git 各环境安装地址 git https git scm com downloads N
  • 接口:mock 模拟数据以及接口调用遇到的 axios的坑

    项目用的 react dva 由于后端接口还没有好 所以需要用mock创数据 拦载 ajax 返回 mock 里面的数据 那么问题来了 怎么用 mock 呢 看了官方文档 我表示没有看明白 问团儿 这个问题 团儿解答 在你现在的里面写 ge
  • upload.addEventListener is not a function报错

    原因 Mock js重写了XMLHttpRequest 导致了原生XMLHttpRequest被mockjs覆盖找不到相应的方法 场景 vite plugin mock vue3 element UI upload组件 解决办法 更改配置项
  • jmockit使用(一) —— mock 系统时间

    一 mock工具被广泛的应用于单测中 尤其是当测试环境系统依赖的外部项较多 而且不受控制时 jmockit一般有2种方式 一种是基于行为的方式 使用者在单测类中写 Expectations 里面放置 预期 会被执行的代码段和返回 这就是一种
  • Java 7 + Rhino 1.7R3 支持 CommonJS 模块吗?

    我需要帮助让 CommonJS 在 Java 7 和 Rhino 1 7R3 上运行 Rhino 1 7R3 支持 CommonJS 模块 https developer mozilla org En New in Rhino 1 7R3
  • java7 / Rhino 中编译和解释的 javascript 的性能

    我对 Java7 中的 Rhino javascript 引擎的性能有一个问题 很快 我的脚本 解析和编译文本 在 Chrome 中的运行速度比 Java7 Rhino 脚本引擎中的运行速度大约快 50 100 倍 我试图找到改善这种情况的
  • JVM 缺少 Rhino

    我有一个使用 ScriptEngine 处理一些 javascript 的项目 并且在我的机器上运行良好 但是当我将项目的 jar 发送到服务器时 我发现服务器的 JVM 没有内置 Rhino 当该代码调用 new ScriptEngine
  • JDK8 中使用的 Rhino javascript JSR-223-wrapper 在哪里?

    我的目的是在 AdaptOpenJDK 8 VM 中提供 JSR 223 javascript 引擎 所以我想到使用已经熟悉的Rhino OpenJDK wiki 文档在这里 https wiki openjdk java net disp
  • 为什么 java newInstance 挂在 getDeclaredConstructors0 处?

    我们使用mozlia rhino生成动态类 然后通过自定义类加载器加载JsClass 如下所示 DynamicClassLoader loader new DynamicClassLoader JavaScriptFactory class
  • Rhino 中没有 Array.filter() 吗?

    为什么我不能使用Array filter 在犀牛 代码是这样的 var simple reason a b c print typeof simple reason filter var not so simple reason new A
  • 锚元素的路径名在 Rhino 中使用 env.js 返回未定义

    我遇到过an issue https github com guardian sbt jasmine plugin issues 17我相信这源于 Rhino 中锚标记的实现 虽然我正在利用env js http www envjs com
  • 在 Rhino 中作为 JavaScript 对象访问 java 地图和列表

    有没有办法在 Rhino 中以 JavaScript 对象的形式访问 Java 地图和列表 我有一个 Map 其中仅包含其他映射以及基元和字符串列表 我想将其传递给 Rhino 脚本并对其执行操作 并将修改后的对象返回到 Java 但因为它
  • js - “间接”调用方法时“this”未定义

    我的目标是从函数表中调用函数来概括命令处理 即间接 很遗憾 this isundefined当这样称呼时 function Server this sessions server this this handlers dummy serve
  • 在 javax.scripting javascript 环境中导入地图

    我在 javax scripting 地图实现中看到一些奇怪的行为 在线示例显示example http java sun com developer technicalArticles J2SE Desktop scripting 添加到
  • Rhino 和并发访问 javax.script.ScriptEngine

    我通过以下方式使用Rhino 1 6r2javax scriptAPI 我知道Rhino引擎声称是多线程 http docs oracle com javase 6 docs api javax script ScriptEngineFac
  • 如何使用 rhino 导入其他 javascript 文件

    我一生都无法弄清楚如何在Rhino下的javascript中导入javascript文件 基本上 我想做的就是导入 some file js 并能够使用其中范围内的内容 我一直在尝试弄乱 Context currentContext com
  • Rhino 和 Spidermonkey JavaScript 引擎有什么区别?

    我第一次开始学习 Javascript 但是一开始我就坚持了两个可能的选择 Rhino 和 Spidermonkey 请您告诉我什么是一个 什么是另一个 以便我可以轻松地为自己选择适合我需要的最佳选择 如果这对您来说更容易 您可以列出两个

随机推荐