简体   繁体   中英

Code coverage in sapui5 OPA5 tests

i can see that in SAPUI5 Qunit tests there is option for checkbox for check the code coverage (by checkbox or with an URL parameter ?coverage) But in OPA5 tests in sapui5 there isn't checkbox for code coverage and if i add the URL parameter ?coverage, the test run regular without code coverage. OPA5 test in sapui5 doesn't support code coverage?

Thanks!

Recently Opa5 introduced component based testing, guessing from 1.34 onwards, the code for calling a component based test looks like

 iStartMyUIComponent({
   componentConfig: {
       name: <foo.my.component.path>
                },
      hash: ""
 });

prior to the component based approach, we only had the option to run the Opa5 tests via an IFrame, the code for calling a frame based test looks like

iStartMyApp: function (oOptions) {
    var sUrlParameters;
    oOptions = oOptions || { delay: 0 };

    sUrlParameters = "serverDelay=" + oOptions.delay;

    this.iStartMyAppInAFrame(getFrameUrl(oOptions.hash, sUrlParameters));
},

A lot of the older examples available use the frame approach which didn't include coverage by default, to get test coverage with the Frame approach you would use something like OpenUi5 Karma with Istanbul.

With component based OpaTests we can now get coverage via the bundled Blanket.js module

see Opa5 with Test Coverage for an example, in this example you will notice the coverage option, the checkbox is checked and there is an additional URL parameter, look down the bottom of the page for the lcov output.

To get the coverage feature in your Qunit runner you'll need to include the following module

jQuery.sap.require("sap.ui.qunit.qunit-coverage");

hth

JSP

Add the following line of code in your opaTest.qunit.html along with other jQuery.sap.require files -

jQuery.sap.require("sap.ui.qunit.qunit-coverage");  // used for code coverage

But make sure you add it after the qunit test files and not before that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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