尝试 运行 qunit 测试时收到 404

Getting a 404 when trying to run a qunit test

我正在使用试用版网站并尝试从 /test-resources 文件夹中 运行 myqunittest.qunit.html。通过使用 url /test-resources/myqunittest.qunit.html。然而,每当我尝试 运行 它时,它只是 returns 一个 404 错误。

这是定义资源的问题吗?我不明白如何找到 view/Main.view.xml 但在 test-resources 文件夹中找不到任何东西(我试过只创建一个简单的 js 或 html 文件包含一行,它仍然是 404'd)。

我直接从 qunit 帮助页面复制了该页面,QUnit Testing Fundamentals,这段代码似乎暗示它应该可以正常工作,而无需参考应用程序的其余部分。

我在两个 html 文件中尝试了 sap.ui.localResources 和 data-sap-ui-resourceroots 的各种组合,但均无济于事。

我的文件夹结构如下:

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>

在您的 index.html 中,您正在相对于资源文件夹中的 index.html 加载 ui5

所以在你的服务器上还有另一个文件夹

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

问题是,您加载的核心也相对于您的测试资源。您可能需要向上移动 1 个目录。

所以在myqunittest.qunit.html 将 bootstrap 更改为

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

此致, 托拜厄斯

SAP WebIDE 将 neo-app.json 添加到您创建的项目中。它包含此条目:

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

这会干扰创建我自己的测试资源文件夹(项目中尚不存在),并导致 404 错误。删除此条目已解决我的问题。