?????????????????????????????л??????????????????Ч?????????????????????д?????????????????????Ч?????????????漰????????????????????????????????????????????????????????????
???????????????????
???????????????????????????????????????????????????飬???????н???????????????????????????????????????????в?????????????????????????????????????????????У??????????????????????????????????2??????????????????????????????BDD(Bebavior Driven Developement?????????????)??TDD(Testing Driven Developement??????????????)??BDD????????????????????????????????????????????????????????????????????????Щ????????????????????????TDD????????д????????????????д?????????????д????????????????????????????????????????С??????????д?????ú???????????????????????????
????BDD??TDD???и???????ó?????BDD???????????????????????????????????????TDD????????????????????????????????Ч?????????????????????????????BDD??TDD????????
????BDD????? - ?????????????????????????????????????????????? - ????????????е????????????? - ???????п???е??????????????????????????????????磬expect?? should?? assert?? - ?趨??????????????????????????????????? - ??????????????????????????????????????′?????????
????TDD????? - ??????????????д???????????????????? - ???????ò????????? - ???????????????????ó?????????????
??????????????????????
?????????????????????????????????mocha??jasmine??qunit?????????????????mocha?????????????????
????· mocha
????mocha?????????????????????????Node??????????????????????????????????????????describe(string?? function)?????????????????it(string?? function)???????????????2???????????????assert???????????true??false??????mocha???????????????????done()??????
????$ npm install mocha
????$ mkdir test
????$ $EDITOR test/test.js # or open with your favorite editor
??????????????
????var assert = require('assert');
????describe('Array'?? function() {
????describe('#indexOf()'?? function() {
????it('should return -1 when the value is not present'?? function() {
????assert.equal(-1?? [1??2??3].indexOf(4));
????});
????});
????});
??????????
????$ ./node_modules/mocha/bin/mocha
????Array
????#indexOf()
????? should return -1 when the value is not present
????1 passing (9ms)
????????mocha???????Promise??
????describe('#find()'?? function() {
????it('respond with matching records'?? function(done) {
????db.find({type: 'User'}?? function(err?? res) {
????if (err) return done(err);
????res.should.have.length(3);
????done();
????});
????});
????});
????});
????· jasmine
????jasmine?????BTT?????????????????????????????describe(string?? function)?????????????????it(string?? function)????????????????2???????????????expect???????????true??false?????????????????Expectation???????????Matcher???????????????????κ?Matcher?????????expect????Matcher?????not????????????????expect(a).not().toBe(false);??
????describe("A suite is just a function"?? function() {
????var a;
????it("and so is a spec"?? function() {
????a = true;
????expect(a).toBe(true);
????expect(a).not().toBe(false);
????});
????});
????jasmine????????????????
describe("long asynchronous specs"?? function() {
beforeEach(function(done) {
done();
}?? 1000);
it("takes a long time"?? function(done) {
setTimeout(function() {
done();
}?? 9000);
}?? 10000);
afterEach(function(done) {
done();
}?? 1000);
});
????· qunit
????qunit??????????jquery????????????????????????????????QUnit.test?????????????????????????????????????????????ж????????????????????????????????
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>QUnit Example</title>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.0.1.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="https://code.jquery.com/qunit/qunit-2.0.1.js"></script>
<script>
QUnit.test( "hello test"?? function( assert ) {
assert.ok( 1 == "1"?? "Passed!" );
assert.equal( null?? false?? "null?? false; equal fails" );
});
</script>
</body>
</html>
????qunit?????????????????????????done()????????
????QUnit.test( "assert.async() test"?? function( assert ) {
????var done = assert.async();
????var input = $( "#test-input" ).focus();
????setTimeout(function() {
????assert.equal( document.activeElement?? input[0]?? "Input was focused" );
????done();
????});
????});
????С????£????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????