$ npm install mocha --save
### 为了操作的方便,请在全局环境也安装一下Mocha
/**
* Created by on 2017/5/16.
*/
const assert = require('assert');
const fs = require('fs');
/**
* supertest请求测试
*/
const superagent = require('superagent');
const app = require('../app');
function request() {
return superagent(app.listen());
}
describe('Array', function() {
describe('#indexOf()', function() {
it('should return -1 when the value is not present', function() {
assert.equal(0, [1,2,3].indexOf(1));
assert.equal(-1, [1,2,3].indexOf(0));
});
});
});
describe('Boolean', function() {
describe('#===', function() {
it('如果 数值型200 全等于 字符型200,返回true', function() {
assert.equal(false, 200 === '200');
});
});
});
/** 断言库组件---should.js
*
*/
const should = require("should");
describe('Should test', function() {
it('number', function() {
(123).should.be.a.Number;
});
it('object property', function() {
const obj = {name:'minghe',email:"minghe36@gmail.com"};
obj.should.have.property('name','minghe');
obj.should.have.property('email');
});
it('ok',function () {
true.should.be.ok;
});
it('equal',function () {
'abc'.should.equal = 'abc';
});
it('not equal',function(){
'abc'.should.not.equal('ddd');
});
it('exist',function(){
const result = {};
should.exist(result);
})
});
describe('fs', function() {
describe('#readFile()', function() {
it('should not be null', function(done) {
fs.readFile('../package.json', 'utf8', function(err,data){
if (err){
return console.error(err);
}
data.should.not.equal(null);
// console.log(data);
done();
});
});
});
});
/**
superagent请求测试
*/
describe('Routes', function () {
describe('GET /', function () {
it('should return 200', function (done) {
request()
.get('/users')
.expect('users', done); //done 是必须传入的,这样请求测试结束后,才能把测试信息推送给mocha处理
});
});
});
测试框架--mocha
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 原文链接:http://www.ruanyifeng.com/blog/2015/12/a-mocha-tutor...
- Spring 也提供了完善的测试框架,我们可以方便的测试Spring Web MVC应用程序。为了使用这个测试框架...
- 通过seleinium IDE 完成脚本的录制之后,可以将其导出为加了python unittest 单元测试框架...