Getting a 404 when trying to run a qunit test

1.3k views Asked by At

I'm using the trial webide and trying to run myqunittest.qunit.html from the /test-resources folder. by using the url /test-resources/myqunittest.qunit.html. However it simply returns a 404 error whenever I attempt to run it.

Is this a problem with defining the resources? I don't understand how, for example, view/Main.view.xml can be found but not anything in the test-resources folder (I've tried just creating a simple js or html file containing a single line and it still 404'd).

I've copied the page directly from the qunit help page, QUnit Testing Fundamentals, this code seems to imply it should just work without any reference to the rest of the app.

I've tried various combinations of sap.ui.localResources and data-sap-ui-resourceroots in both html files to no avail.

My folder structure is as follows:

myapp
    test-resources
        myqunittest.qunit.html
    view
        Main.controller.js
        Main.view.xml
    index.html

myqunittest.qunit.html

<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <script id="sap-ui-bootstrap" 
     type="text/javascript"
     src="resources/sap-ui-core.js"
     data-sap-ui-theme="sap_bluecrystal"
     data-sap-ui-noConflict="true">
    </script>

    <link rel="stylesheet" href="resources/sap/ui/thirdparty/qunit.css" type="text/css" media="screen" />
    <script type="text/javascript" src="resources/sap/ui/thirdparty/qunit.js"></script>
    <script type="text/javascript" src="resources/sap/ui/qunit/qunit-junit.js"></script>
    <script type="text/javascript" src="resources/sap/ui/qunit/QUnitUtils.js"></script>


</head>
<body>
    <div id="qunit"></div>
</body>
</html>

index.html

<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>

    <script src="resources/sap-ui-core.js"
            id="sap-ui-bootstrap"
            data-sap-ui-libs="sap.m"
            data-sap-ui-resourceroots='{"myapp": "./"}'
            data-sap-ui-theme="sap_bluecrystal">
    </script>

    <script>
            sap.ui.localResources("view");

            var app = new sap.m.App({initialPage:"idMain"});
            var page = sap.ui.view({id:"idMain", viewName:"myapp.view.Main", type:sap.ui.core.mvc.ViewType.XML});
            app.addPage(page);
            app.placeAt("content");
    </script>

</head>
<body class="sapUiBody" role="application">
    <div id="content"></div>
</body>
</html>
2

There are 2 answers

1
MKHC On BEST ANSWER

The SAP WebIDE adds neo-app.json to a project you create. It contains this entry:

{
    "path": "/test-resources",
    "target": {
        "type": "service",
        "name": "sapui5",
        "entryPath": "/test-resources"
    },
    "description": "SAPUI5 Test Resources"
}

This is interfering with creating my own test-resources folder (one doesn't already exist in the project), and was causing the 404 error. Removing this entry has fixed my problem.

1
TobiasOetzel On

In your index.html you are loading ui5 relatively to the index.html in a resources folder

so on your server there is another folder

myapp
    resources
        sap-ui-core.js
    test-resources
        myqunittest.qunit.html
    view
        Main.controller.js
        Main.view.xml
    index.html

The problem is, that you are loading the core also relatively to your test-resources. You probably need to go 1 directory up.

so in myqunittest.qunit.html change the bootstrap to

<script src="../resources/sap-ui-core.js"

Best regards, Tobias