简体   繁体   English

如何测试用户界面小部件?

[英]How do I test user interface widgets?

In angular, and in javascript in general, how to unit test action like, clicking a button should show dialog box, clicking the same button when the box is shown hides the box. 在角度和一般的javascript中,如何单元测试动作,如单击按钮应该显示对话框,当显示框时单击相同的按钮隐藏框。 My question is how to test elements dom attributes ? 我的问题是如何测试元素dom属性? In GWT a pattern design called MVP ( Model View Controller ). 在GWT中,称为MVP(模型视图控制器)的模式设计。 Where The controller is tests but, not the view ! 控制器在哪里测试但不是视图!

This has already been answered here to some degree: How to test behavior in the link function of a directive 这在某种程度上已经得到了回答: 如何在指令的link函数中测试行为

Angular's test suite of choice is Jasmine . Angular的首选测试套件是Jasmine Basically what you need to do, in angular is $compile your directive, then use browserTrigger() to interact with the DOM elements it produces however you need to, then test the outcomes in your $scope. 基本上你需要做什么,在angular中是$compile你的指令,然后使用browserTrigger()与它产生的DOM元素进行交互,然后你需要,然后在$ scope中测试结果。

Angular is 100% BUILT WITH TESTABILITY IN MIND. Angular 100%内置,具有测试能力。 Products like Selenium shouldn't be necessary. 像Selenium这样的产品不是必需的。

If you need more examples. 如果您需要更多示例。 I highly recommend just hopping into Angular's Git repository , and looking at their directive tests . 我强烈建议您跳转到Angular的Git存储库 ,并查看他们的指令测试

You can use some front end testing suites such as cucumber or selenium to write front end test suites to check browser behavior. 您可以使用诸如黄瓜硒之类的一些前端测试套件来编写前端测试套件,以检查浏览器的行为。 You can then set up the test suites to also run on multiple browsers to have a solid platform for dom testing. 然后,您可以将测试套件设置为也可以在多个浏览器上运行,以具有用于dom测试的可靠平台。

Vojta Jina(AngularJS团队的成员)对此有一些出色的注释和示例代码: https : //github.com/vojtajina/ng-directive-testing

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

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