嘲讽和量角器打桩 [英] Mocking and Stubbing with protractor

查看:139
本文介绍了嘲讽和量角器打桩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想测试我用量角器角应用程序。
该应用程序有一个会谈到服务器API模块
在这些测试中,我想这个模拟API模块。
我不想做完整的集成测试,但测试用户输入与来自API的预期值。
这不仅会这样使客户端的测试速度更快,这也将让我测试的边缘情况下,如连接错误。

I want to test my angular app with protractor. The app has an API Module that talks to the server During these tests I want to mock this Api Module. I don't want to do full integration tests, but tests from the user input with expected values from the API. Not only could this make the client tests faster, it would also allow me to test for edge cases, like connection errors.

我怎样才能做到这一点用量角器?
我刚开始安装集成测试。

How can I do this with protractor? I just started to setup integration tests.

我用量角器NPM模块,安装硒,调整默认的配置和使用的<一个href=\"https://github.com/angular/protractor/blob/master/example/onProtractorRunner.js\">onProtractorRunner.js验证我的设置工作。

I used the npm protractor module, installed selenium, adjusted the default config and used the onProtractorRunner.js to verify my setup works.

什么是嘲讽的推荐的方法?
我认为嘲讽,必须在浏览器中直接在测试文件完成的,而不是。
我认为在测试文件中的命令是量角器具体和将被发送到所述硒参赛者。因此,会话和测试过程中,我不能分享的JavaScript对象。

What is the recommended way of mocking? I assume that the mocking has to be done within the browser and not directly in the test file. I assume that the commands in the test file are protractor specific and will be sent to the selenium runners. Therefore I can't share javascript objects during the session and the test.

不知何故,我期望我会需要一个间谍的库如 sinon.js 或者这已经包含在量角器?

I somehow expect that I will need a spy library like sinon.js or is this already included in protractor?

编辑:我读到在量角器问题跟踪这个问题,这可能是一个办法做到这一点。
基本上你写测试中的模拟模块,发送在浏览器中执行/应用范围。

I read about this issue in the protractor issue tracker, which could be a way to do it. Basically you write a Mock Module in the test, that is sent to be executed in the browser/ the applications scope.

编辑:这里有更多有前途的问题。了解加嘲弄的角度应用第一会谈。
了解第二次会谈嘲讽后端

Here are more promising Issues. The first talks about adding Mocks to the Angular App. The second talks about mocking the backend.

这看起来真的不错,在这种情况下角应用会留在它原来的样子。然而,这目前只适用于去precated NG-场景。

This looks really nice, in this case the Angular App would stay in it's original form. However this currently only works with the deprecated ng-scenarios.

推荐答案

此博客帖子讨论量角器提前使用场景。尤其是,它涵盖了小诀窍 addMockModule()量角器浏览器对象方法。该方法允许你创建(您的API模块,即嘲笑或存根)的量角器角模块,并将其上传到浏览器,以取代一个给定的规范的范围内真正实现或将规范的。

This blog post discusses advance usage scenarios for Protractor. In particular it covers the the little know addMockModule() method of the Protractor browser object. The method allows you to create angular modules in Protractor (i.e. mocks or stubs of your API module) and upload them to the browser to replace the real implementation within the context of a given spec or set of specs.

这篇关于嘲讽和量角器打桩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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