如何从命令行在Node.js上运行Jasminetesting

如何从命令行上运行Node.js的Jasminetesting? 我通过npm安装了jasmine-node并编写了一些testing。 我想在spec目录下运行testing,并在terminal中得到结果,这可能吗?

编辑

看来这不再是当前最好的答案,因为这个包是无人维护的。 请看下面的答案


你可以这样做

从你的testing目录

 sudo npm install jasmine-node 

这将茉莉花安装到../node_modules/jasmine-node中

然后

 ../node_modules/jasmine-node/bin/jasmine-node --verbose --junitreport --noColor spec 

从我的演示这样做

 Player - 5 ms should be able to play a Song - 2 ms when song has been paused - 1 ms should indicate that the song is currently paused - 0 ms should be possible to resume - 0 ms tells the current song if the user has made it a favorite - 1 ms #resume - 0 ms should throw an exception if song is already playing - 0 ms Player - 5 ms should be able to play a Song - 2 ms when song has been paused - 1 ms should indicate that the song is currently paused - 0 ms should be possible to resume - 0 ms tells the current song if the user has made it a favorite - 1 ms #resume - 0 ms should throw an exception if song is already playing - 0 ms Finished in 0.01 seconds 5 tests, 8 assertions, 0 failures, 0 skipped 

这应该让你快点:

  1. 安装Node.js(显然)。
  2. 接下来安装茉莉花。 打开命令提示符并运行:

    npm install -g jasmine

  3. 接下来,cd到任何目录,并设置一个“项目”的例子:

    jasmine init
    jasmine examples

  4. 现在运行你的unit testing:

    jasmine

如果你的jasmine.json文件在spec / support / jasmine.json以外的地方,只需运行:

jasmine JASMINE_CONFIG_PATH=relative/path/to/your/jasmine.json

更多信息请参阅:

尝试Karma(以前是Testacular),它是由Angular.js团队完成的testing库不可知testing运行者

http://karma-runner.github.io/0.12/index.html

茉莉花的支持很好。

http://karma-runner.github.io/0.12/intro/how-it-works.html