简体   繁体   English

如何使用Qunit显示多个测试

[英]How to display multiple tests with Qunit

The code below has two functions being tested. 下面的代码具有两个正在测试的功能。 The contents of these two functions is completely irrelevant. 这两个功能的内容是完全无关的。 Below these two functions are two additional test functions of which each is testing one of the two previous functions. 在这两个功能下面是两个附加的测试功能,其中每个功能都在测试前面两个功能之一。

The problem 问题

The only output I get in the Qunit display is the results of the first test function which in this case is "add function". 我在Qunit显示屏中获得的唯一输出是第一个测试功能的结果,在这种情况下,该功能为“添加功能”。 I would like to see both and any additional tests in the same output. 我希望在同一输出中看到这两个以及任何其他测试。 Am I missing some syntax that tells Qunit that I want to see the test results of both? 我是否缺少告诉Qunit我想查看两者的测试结果的语法?

Thank you. 谢谢。

Code

function add(a,b){
    return a+b;
};

var answer = add(2,2);


function mathy(a,b,callback){

    return callback(a,b)
}

var mathFunc = mathy(2,2,add)



// Test one

test( "add function", function() {
       ok(answer === 4);

});


// Test2


test( "callback function", function() {

       ok(mathFunc === 4)
});

Use the Qunit autostart flag and the init() and start() methods to run the tests manually: 使用Qunit autostart标志以及init()start()方法来手动运行测试:

function add(a,b){
    return a+b;
};

var answer = add(2,2);


function mathy(a,b,callback){

    return callback(a,b)
}

var mathFunc = mathy(2,2,add)

QUnit.config.autostart = false;
QUnit.init();
QUnit.start();


// Test one

test( "add function", function() {
       ok(answer === 4);

});


// Test2


test( "callback function", function() {

       ok(mathFunc === 4)
});

References 参考文献

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM