原文:state of testing in UI5: OPA5, UIVeri5 and wdi5
测试作为确保 UI5 利用程序开发投资的一种伎俩曾经变得越来越广泛。
为了进一步推动这个问题,让咱们评估 UI5 中最突出的端到端测试框架。
所有这三个都容许测试面向用户的性能,“像用户一样”操作 UI5 应用程序:与 UI 元素交互。
UIVeri5 和 wdi5 都能够近程管制浏览器。 也就是说,它们有一个不同于 UI5 应用程序的运行时。 因而,两者都须要一个(网络)服务器,以便连贯到运行测试中的 UI5 应用程序。
OPA5 的不同之处在于它与 UI5 应用程序共享雷同的运行时——它与被测 UI5 应用程序相邻工作,而不是离开。
(QUnit 不在本文中,因为咱们专一于运行面向用户的测试,而不是纯正的功能测试。)
此外,wdi5 容许在挪动设施上测试混合应用程序。 它能够连贯到 iOS、Android 和 Electron 上应用cordova 封装的UI5 应用程序,并运行与基于浏览器的应用程序雷同的测试。
OPA5
OPA5 自带 UI5,不须要额定的装置步骤。 然而它的设置并不直观,混合了 OPA5 的根本 QUnit,并且须要几个蕴含级别。
上面是一些例子:
webapp/test/integration/opaTests.qunit.html:
<!-- ... --> <script src="opaTests.qunit.js"></script></head><body> <div id="qunit"></div> <!-- ... -->
webapp/test/integration/opaTests.qunit.js:
sap.ui.getCore().attachInit(function () { "use strict"; sap.ui.require([ // all test suites aggregated in here "test/Sample/test/integration/AllJourneys" ], function () { // `OPA5`'s mama :) QUnit.start(); });});
webapp/test/integration/AllJourneys.js:sap.ui.define([ "./arrangements/Startup", // arrangements "./NavigationJourney", // actions + assertions "./BindingJourney", // actions + assertions "./InteractionJourney" // actions + assertions], /* ... */
excerpt from webapp/test/integration/BindingJourney.js:
sap.ui.define(["sap/ui/test/opaQunit", "./pages/Main", "./pages/Other"], function (opaTest) { "use strict"; QUnit.module("Binding Journey"); QUnit.module("Other view: PeopleList: items aggregation"); opaTest("bound status", function (Given, When, Then) { Given.iStartMyApp(); When.onTheAppPage.iPressTheNavButton(); Then.onTheOtherView.iShouldSeeTheList().and.theListShouldBeBound(); });// ...
应用上面的 url 启动:
http://localhost:1081/test/in...
uiveri5
UIVeri5 须要 Node.js >=8 并通过规范 npm 命令 npm install @ui5/uiveri5 装置。
而后通过配置文件和蕴含测试代码的文件进行设置——确保两者都在同一个文件 sys 文件夹中。
配置文件:
exports.config = { profile: "integration", baseUrl: "http://localhost:1081/index.html"};
而后能够启动 UIVeri5
- 首先启动网络服务器:yarn dev(或yarn start:ci)
- yarn test:uiveri5
OPA5 速度快于 UIVeri5,因为它与 UI5 共享运行时,从而节俭了基础设施开销,例如启动浏览器自身。然而,当须要更高级的测试行为时,它很快就会达到其极限,例如 UI5 控件之间的穿插交互或对 UI5 控件以外的元素进行操作。此外,嵌套的 waitFor 操作感觉很蠢笨。
应用 UIVeri5,能够真正以内部用户的身份操作 UI,包含 UI5 控件之外的元素和性能。然而 UIVeri5 的外围(Protractor、WebdriverJS)感觉曾经过期了,外围元素之间的连贯代码有时会短少最初的实现里程(例如不可能在 conf.js 中设置日志级别?!)。某些限度,例如套件名称(形容)和文件名之间的强制关联也会减少这种印象。可怜的是,在测试时控件上只有 UI5 API 办法的一个子集可用。此外,文档仿佛是零散的——但在文档中有点暗藏,UIVeri5 具备预构建的身份验证器,其中包含 SAP Cloud Platform SAP ID。
更多Jerry的原创文章,尽在:"汪子熙":