[英]Angular E2E test data: ngMockE2E or test data server?
I am developing an Angular app (Angular 1.1.5). 我正在开发一个Angular应用程序(Angular 1.1.5)。 I need some way of mocking REST API responses for e2e tests.
我需要一些模拟REST API响应以进行e2e测试的方法。
AngularJS (Green & Seshadri) goes into some detail on unit testing HTTP requests with $httpBackend
, but has little to say about e2e tests. AngularJS(Green&Seshadri)详细介绍了使用
$httpBackend
进行HTTP请求的单元测试,但是关于$httpBackend
测试则无话可说。
The documentation suggests using the ngMockE2E
module to mock $httpBackend
(which is distinct from the normal unit testing $httpBackend
mock. 该文档建议使用
ngMockE2E
模块来模拟$httpBackend
(这与正常的单元测试$httpBackend
模拟不同。
I spent a few hours investigating the ngMockE2E
API and, whilst I can see some benefits, there seem to be many downsides. 我花了几个小时研究
ngMockE2E
API,尽管我看到了一些好处,但似乎还有很多缺点。 My question is: 我的问题是:
What are the advantages of ngMockE2E
over a simple server that provides test responses? 与提供测试响应的简单服务器相比,
ngMockE2E
有什么优势? or, more generally, What is the best way to test an Angular app's interactions with a server? 或者,更一般而言, 什么是测试Angular应用与服务器交互的最佳方法?
I can think of a few disadvantages: 我可以想到一些缺点:
ngMockE2E
and my actual application module) ngMockE2E
和我的实际应用程序模块的新模块)来引导应用程序 /resource/:id
, I'd need to give a regex to match the URL ( \\/resource\\/.+$
), then split the matching URL string on slash and pick the last element. /resource/:id
获取id参数,则需要提供一个正则表达式以匹配URL( \\/resource\\/.+$
),然后在斜杠上拆分匹配的URL字符串并选择最后一个元素。 I can also think of some advantages. 我还可以想到一些优点。 When using
ngMockE2E
: 使用
ngMockE2E
:
$httpBackend
will inspect all HTTP requests for matches. $httpBackend
将检查所有 HTTP请求是否匹配。 Very interested in thoughts and experiences. 对思想和经验非常感兴趣。
My conclusion, several weeks of development later: I found a simple dummy backend (Node/Express) more flexible and maintanable than the e2e testing mock backend. 我的结论是,经过几周的开发:我发现一个简单的虚拟后端(Node / Express)比e2e测试模拟后端更灵活和可维护。 The most compelling reasons are proper URL pattern matching and real HTTP requests for browser debugging.
最引人注目的原因是正确的URL模式匹配和用于浏览器调试的真实HTTP请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.