Search code examples
javascripttestingqunitsapui5

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!


Solution

  • 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