2013-09-22 64 views
6

是否有可能只用一些测试运行nodeunit测试文件中的一个测试。我tests.js文件:通过名称从一个节点单元文件运行一个测试

module.exports = { 
    test2: function (test) { 
     console.log ("test2") 
     test.done(); 
    }, 
    test1: function (test) { 
     console.log ("test1") 
     test.done(); 
    } 
}; 

我可以运行所有测试:

$ nodeunit tests.js 

但我想只运行test2的,如:

$ nodeunit tests.js test2 

是否有可能不劈裂文件tests.js成2个独立的文件?

回答

6

nodeunit -h可用的选项(这是0.8.1版本):

Usage: nodeunit [options] testmodule1.js testfolder [...] 
Options: 

    --config FILE  the path to a JSON file with options 
    --reporter FILE optional path to a reporter file to customize the output 
    --list-reporters list available build-in reporters 
    -t name,   specify a test to run 
    -f fullname,  specify a specific test to run. fullname is built so: "outerGroup - .. - innerGroup - testName" 
    -h, --help  display this help and exit 
    -v, --version  output version information and exit 

所以从以下应该做你想要什么:

$ nodeunit tests.js -t test2 

如:

$ nodeunit ./tests.js -t test2 

tests.js 
test2 
✔ test2 
相关问题