JsUnit 案例必须与 JsUnit 位于同一目录下吗?

发布于 2024-08-25 18:11:54 字数 1309 浏览 3 评论 0原文

我已经安装了 JsUnit 和一个测试用例,如下所示:

/home/chernevik/Programming/JavaScript/jsunit
/home/chernevik/Programming/JavaScript/jsunit/testRunner.html
/home/chernevik/Programming/JavaScript/jsunit/myTests/lineTestAbs.html
/home/chernevik/Programming/JavaScript/lineTestAbs.html

当我在浏览器中将测试运行器作为文件打开,并从 jsunit/myTests 目录测试 lineTestAbs.html 时,它会通过。当我从 JavaScript 目录测试同一文件时,测试运行程序超时,询问该文件是否存在或者是测试页面。

问题: 我在这里做错了什么,还是这是预期的行为? 是否可以将测试用例放在不同的目录结构中,如果可以,JsUnitCore.js 的正确路径引用是什么? 如果从 HTTP 服务器检索文件,JsUnit 的行为是否会有所不同?

<html>
    <head>
        <title>Test Page line(m, x, b)</title>
        <script language="JavaScript" src="/home/chernevik/Programming/JavaScript/jsunit/app/jsUnitCore.js"></script>
        <script language="JavaScript">
            function line(m, x, b) {
                return m*x + b;
                }

            function testCalculationIsValid() {
                assertEquals("zero intercept", 10, line(5, 2, 0));
                assertEquals("zero slope", 5, line(0, 2, 5));
                assertEquals("at x = 10", 25, line(2, 10, 5));
                }
        </script>
    </head>
    <body>
        This pages tests line(m, x, b).
    </body>
</html>

I have installed JsUnit and a test case as follows:

/home/chernevik/Programming/JavaScript/jsunit
/home/chernevik/Programming/JavaScript/jsunit/testRunner.html
/home/chernevik/Programming/JavaScript/jsunit/myTests/lineTestAbs.html
/home/chernevik/Programming/JavaScript/lineTestAbs.html

When I open the test runner in a browser as a file, and test lineTestAbs.html from the jsunit/myTests directory, it passes. When I test the same file from the JavaScript directory, the test runner times out, asking if the file exists or is a test page.

Questions:
Am I doing something wrong here, or is this the expected behavior?
Is it possible to put test cases in a different directory structure, and if so what is the proper path reference to to JsUnitCore.js?
Would JsUnit behave differently if the files were retrieved from an HTTP server?

<html>
    <head>
        <title>Test Page line(m, x, b)</title>
        <script language="JavaScript" src="/home/chernevik/Programming/JavaScript/jsunit/app/jsUnitCore.js"></script>
        <script language="JavaScript">
            function line(m, x, b) {
                return m*x + b;
                }

            function testCalculationIsValid() {
                assertEquals("zero intercept", 10, line(5, 2, 0));
                assertEquals("zero slope", 5, line(0, 2, 5));
                assertEquals("at x = 10", 25, line(2, 10, 5));
                }
        </script>
    </head>
    <body>
        This pages tests line(m, x, b).
    </body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

演出会有结束 2024-09-01 18:11:54

我认为这是 Firefox 或其他非 IE 浏览器中 Javascript 实现的一个错误。
如果你用IE就不会有问题。

I think this is a bug in the implementation of Javascript in Firefox or other non-IE browsers.
If you use IE there would be no problem.

浪推晚风 2024-09-01 18:11:54

本地文件资源应以 file:// 为前缀
将 jsUnitCore.js 拖到浏览器中,然后将地址栏中获得的 url 复制回源中。

A local file resource should be prefixed by file://
Drag jsUnitCore.js into your browser, then copy the url you get in the location bar back into your source.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文