简体   繁体   English

在角度4项目中模拟休息调用功能性e2e量角器测试

[英]Mocking rest calls in functional e2e protractor tests in angular 4 project

We have a huge project and we have written a lot of test cases to cover a lot of real scenario user behavior in our e2e functional test cases. 我们有一个庞大的项目,我们已经编写了大量的测试用例来涵盖我们的e2e功能测试用例中的许多真实场景​​用户行为。

As the test goes on, it makes a lot of rest calls to complete the test cases. 随着测试的进行,它会进行大量的休息调用以完成测试用例。 When we cover different browser in sauce lab it multiplies 5-9 times. 当我们在酱料实验室中覆盖不同的浏览器时,它会倍增5-9倍。

What I want is to mock all the rest calls so that there will not be any real calls to the actual server but internally it will be handled. 我想要的是模拟所有其余的调用,以便不会对实际服务器进行任何实际调用,但在内部将对其进行处理。 its for functional e2e test not unit test as we mocked all unit tests using jasmine spyOn . 它用于功能性e2e测试而非单元测试,因为我们使用jasmine spyOn所有单元测试。

I have explored json-server and $httpBackend of protractor. 我已经探索了json-server$httpBackend的量角器。 son-server did not fit as it does not handles app post, put, delete calls well. son-server不合适,因为它不能很好地处理app post,put,delete。 in case of $httpBackend 在$ httpBackend的情况下

I have gone through this post and its for andularJs app not angular app and also its all about single rest call mocking for angularJs not for all rest calls. 我已经完成了这篇文章 ,它的forularJs应用程序不是角度应用程序,而且它的所有关于单个休息调用mockJs而不是所有休息调用。

Also looked this angularjs multi mock for angularjs and its also for angularjs not angular and looks like this changes the original rest url for query parameter. 另外看了这个angularjs multi mock for angularjs ,它也适用于angularjs而不是angular,看起来这样会改变查询参数的原始rest url。

Mocking network calls is not supported yet by Protractor for Angular 2+ applications. Protractor for Angular 2+应用程序尚不支持模拟网络调用。 See this post and the corresponding issue on github. 在github上查看这篇文章相应的问题

Personnally, I used ng-apimock plugin to mock all network calls to the backend with a proxy. 个人而言,我使用ng-apimock插件来模拟使用代理的后端的所有网络调用。

It works really well and is simple to configure. 它工作得很好,配置简单。 Just follow the configuration for Angular application here 只要按照角应用程序的配置在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM