QUnit Tutorial
QUnit Useful Resources
Selected Reading
- QUnit - Nested Modules
- QUnit - Callbacks
- QUnit - Expect Assertions
- QUnit - Async Call
- QUnit - Only Test
- QUnit - Skip Test
- QUnit - Execution Procedure
- QUnit - Using Assertions
- QUnit - API
- QUnit - Basic Usage
- QUnit - Environment Setup
- QUnit - Overview
- QUnit - Home
QUnit Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
QUnit - Callbacks
QUnit - Callbacks
在将QUnit纳入其他工具(如CI服务器)时,这些反馈可用作测试结果的APIC。 下面是带有实例的QUnit呼应器方法的执行程序。
<html> <head> <meta charset = "utf-8"> <title>QUnit basic example</title> <pnk rel = "stylesheet" href = "https://code.jquery.com/qunit/qunit-1.22.0.css"> <script src = "https://code.jquery.com/qunit/qunit-1.22.0.js"></script> </head> <body> <span id = "qunit"></span> <span id = "qunit-fixture"></span> <script> //Register a callback to fire whenever a testsuite starts. QUnit.begin(function( details ) { var data = document.getElementById("console").innerHTML; document.getElementById("console").innerHTML = "<br/>" + "QUnit.begin- Test Suite Begins " + "<br/>" + "Total Test: " + details.totalTests; }); //Register a callback to fire whenever a test suite ends. QUnit.done(function( details ) { var data = document.getElementById("console").innerHTML; document.getElementById("console").innerHTML = data + "<br/><br/>" + "QUnit.done - Test Suite Finised" + "<br/>" + "Total: " + details.total + " Failed: " + details.failed + " Passed: " + details.passed; }); //Register a callback to fire whenever a module starts. QUnit.moduleStart(function( details ) { var data = document.getElementById("console").innerHTML; document.getElementById("console").innerHTML = data + "<br/><br/>" + "QUnit.moduleStart - Module Begins " + "<br/>" + details.name; }); //Register a callback to fire whenever a module ends. QUnit.moduleDone(function( details ) { var data = document.getElementById("console").innerHTML; document.getElementById("console").innerHTML = data + "<br/><br/>" + "QUnit.moduleDone - Module Finished " + "<br/>" + details.name + " Failed/total: " + details.failed +"/" + details.total ; }); //Register a callback to fire whenever a test starts. QUnit.testStart(function( details ) { var data = document.getElementById("console").innerHTML; document.getElementById("console").innerHTML = data + "<br/><br/>" + "QUnit.testStart - Test Begins " + "<br/>" + details.module +" " + details.name; }); //Register a callback to fire whenever a test ends. QUnit.testDone(function( details ) { var data = document.getElementById("console").innerHTML; document.getElementById("console").innerHTML = data + "<br/><br/>" + "QUnit.testDone - Test Finished " + "<br/>" + details.module +" " + details.name + "Failed/total: " + details.failed +" " + details.total+ " "+ details.duration; }); QUnit.module( "Module A", { beforeEach: function( assert ) { assert.ok( true, "before test case" ); }, afterEach: function( assert ) { assert.ok( true, "after test case" ); } }); QUnit.test( "test case 1", function( assert ) { assert.ok( true, "Module A: in test case 1" ); }); QUnit.test( "test case 2", function( assert ) { assert.ok( true, "Module A: in test case 2" ); }); QUnit.module( "Module B" ); QUnit.test( "test case 1", function( assert ) { assert.ok( true, "Module B: in test case 1" ); }); QUnit.test( "test case 2", function( assert ) { assert.ok( true, "Module B: in test case 2" ); }); </script> <span id = "console" ></span> </body> </html>
Verify the Output
你应当看到以下结果:
Advertisements