JsUnit 案例必须与 JsUnit 位于同一目录下吗?
我已经安装了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这是 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.
本地文件资源应以
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.