南特JavaScript 单元测试

发布于 2024-10-30 18:18:12 字数 440 浏览 4 评论 0原文

下,我想要通过 Nant 脚本对我的 javascript 进行单元测试的最简单方法,我理想的用法是告诉它我的 src javascript 文件所在的位置,然后给它另一个文件夹,其中我的所有测试 javascript 文件所在......

理想情况 在互联网上进行侦察,似乎有两层,一层是实际的测试库,另一层是测试运行器。

至于实际的测试库,我希望它类似于 N/JUnit,我知道有 JSUnit,但它似乎不能按照我想要的方式使用,我确实找到了不同版本的 JSUnit (1.3)它可以与 Ant 一起使用,但将其放入 Nant 中似乎需要做大量的工作。

就跑步者而言,我不关心它在浏览器中运行的东西...我对我的 src js 代码使用 MVP 类方法,所以虽然底层视图使用 Jquery,但它都会被模拟出来,所以它不太这是一个很大的问题...

任何显示我如何将其连接到 Nant 的例子都会很棒!

I am ideally after the simplest way to unit test my javascript via my Nant script, my ideal usage would be telling it where my src javascript files reside, then giving it another folder where all my test javascript files reside....

From my quick scout on the interwebs it seems that there are 2 layers to this, one being the actual testing library, then the other being the test runner.

As far as the actual testing library I would like it to be similar to N/JUnit, I know there is JSUnit but it doesnt seem like it can be used in the way I want, I did find a different version of JSUnit (1.3) which can be used with Ant, but it seemed to be an awful lot of work to get it put into Nant.

As far as the runner I dont care about it running things in the browser... I am using a MVP sort of approach to my src js code, so although the underlying view uses Jquery it would all be mocked out, so its not too much of an issue...

Any examples showing how I could hook it into Nant would be great!

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

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

发布评论

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

评论(1

天荒地未老 2024-11-06 18:18:12

忘记了这个问题在这里...

我最终使用 JsTestDriver 进行自动化单元测试,我已将其插入 nant 使用:

<target name="javascript-tests" description="Run the Javascript test runner and test">
    <exec program="${file.java}">
        <arg line="-jar ${dir.tools}\js-test-driver\JsTestDriver-1.3.2.jar"/>
        <arg line="--config ${dir.tools}\js-test-driver\JsTestDriver.conf"/>
        <arg line="--port 4224"/>
        <arg line='--browser "${file.firefox}"'/>
        <arg line="--tests all"/>
    </exec>
</target>

我遇到了一个恼人的问题,该问题没有在任何地方记录,只是在提出其他一些问题后才偶然发现,但它出现在我使用的版本上,它无法与相对路径一起正常工作,但在conf文件中,我有基本路径变量,该变量被我的构建脚本替换为令牌:

# Server url
server: http://localhost:4224 

# Base dir for relative lookups
basepath: D:\Code\myproject

load:
  # Includes

它运行我的所有测试并告诉我它们是否通过或失败了,这就是我所追求的......我希望这能让其他人快速启动并运行......

Forgot this question was on here...

I ended up using JsTestDriver for my automated unit testing, I have plugged this into nant using:

<target name="javascript-tests" description="Run the Javascript test runner and test">
    <exec program="${file.java}">
        <arg line="-jar ${dir.tools}\js-test-driver\JsTestDriver-1.3.2.jar"/>
        <arg line="--config ${dir.tools}\js-test-driver\JsTestDriver.conf"/>
        <arg line="--port 4224"/>
        <arg line='--browser "${file.firefox}"'/>
        <arg line="--tests all"/>
    </exec>
</target>

I faced an annoying issue, which was not documented anywhere and only happened to stumble across after asking some other questions, but it appears on the version I was using it would not work correctly with relative paths, but in the conf file I have the basepath variable which is token replaced by my build script:

# Server url
server: http://localhost:4224 

# Base dir for relative lookups
basepath: D:\Code\myproject

load:
  # Includes

That runs all my tests and tells me if they passed or failed, which is what I was after... I hope this gets someone else up and running quickly...

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