mocha测试接口类型及测试报告收集
记录参考:
参考文档:
测试报告以及es6:
http://www.ruanyifeng.com/blog/2015/12/a-mocha-tutorial-of-examples.html
测试接口类型:
https://blog.csdn.net/hustzw07/article/details/73920809
参数
之前我们写 Mocha测试用例的时候,主要用 describe(), it() 组织用例。这跟 Jasmine 风格是类似的。实际上,这只是 Mocha 支持的一种而已。
在命令行中,有如下命令可供我们选择。
- -u, --ui <name> specify user-interface (bdd|tdd|qunit|exports)
默认情况下,Mocha使用 bdd 帮我们执行 describe(), it() 的用例。
- describe('#indexOf()', function(){
- it('should return -1 when not present', function(){
- [1,2,3].indexOf(4).should.equal(-1);
- });
- });
我们也可以选择其他接口类型。比如 tdd。
Mocha的测试接口类型指的是集中测试用例组织模式的选择,更像是为用户提供几种组织测试用例的方式。
BDD
BDD行为驱动开发,全名 Behavior Driven Development。
Mocha默认的测试接口。 BDD测试接口提供 describe(), context(), it(), specify(), before(), after(), beforeEach(), 和 afterEach()几种函数,其中context函数只是describe函数的别名,specify函数也是it函数的别名。
另外,Jasmine的测试风格就是bdd,它的特征就是使用describe,it。 对 BDD 有兴趣的可以去这个网站看下
http://jbehave.org/introduction.html
TDD
TDD,测试驱动开发(Test-Driven Development)
TDD接口提供 suite(), test(), suiteSetup(), suiteTeardown(), setup(), 和 teardown()函数,用例写法如下:
- suite('#indexOf()', function(){
- test('should return -1 when not present', function(){
- ([1,2,3].indexOf(4)).should.be.eql(-1);
- });
- });
tdd跟bdd区别在于,它使用suite,test,suiteSetup,suiteTeardown,setup,teardown 等函数。
Exports
exports 跟 node 里的模块语法很像,before, after, beforeEach, and afterEach 都是作为对象的属性,其它对象的值默认是 suite,属性是函数的话,代表是一个test。简单来说,除了钩子函数,对象是 测试集, 属性是 测试用例。
- require("should");
- module.exports = {
- before: function(){
- // ...
- },
- 'Array': {
- '#indexOf()': {
- 'should return -1 when not present': function(){
- [1,2,3].indexOf(4).should.equal(-1);
- }
- }
- }
- };
钩子函数
从 BDD 到 TDD,describe 和 it 变变成了 suite, test。对应的钩子函数也变了。那它们的行为有没有改变呢?下面是个例子。
- var assert = require('assert');
- var mocha = require('mocha');
- require("should");
- suite('Array', function(){
- suiteSetup(function(){
- console.log();
- console.log('-----------suiteSetup');
- });
- suiteTeardown(function(){
- console.log('-----------suiteTeardown');
- console.log();
- });
- setup(function(){
- console.log();
- console.log('-----------setup');
- });
- teardown(function(){
- console.log('-----------teardown');
- console.log();
- });
- test('First layer', function(){
- ([1,2,3].indexOf(4)).should.eql(-1);
- });
- suite('Second layer', function(){
- suiteSetup(function(){
- console.log();
- console.log('-----------Second layer suiteSetup');
- });
- setup(function(){
- console.log();
- console.log('-----------Second layer setup');
- });
- test('Second layer test', function(){
- ([1,2,3].indexOf(4)).should.eql(-1);
- });
- });
- });
输出
mocha测试接口类型及测试报告收集的更多相关文章
- postman测试接口各种类型传值
postman测试接口各种类型传值 标签: postman测试 json串 Map 2018年01月27日 02:32:00 145人阅读 评论(0) 收藏 举报 1.Map类型或实体类类型传值,即j ...
- 使用mocha测试
学习了MOCHA官网的示例,将学习成果记录一下.[原文+例子:使用mocha测试] mocha是什么 Mocha是一个跑在node和浏览器上的javascript测试框架,让异步测试变得简单有趣, 并 ...
- (转)无法将类型为“Microsoft.Office.Interop.Word.ApplicationClass”的 COM 对象强制转换为接口类型“Microsoft.Office.Interop.Word._Application”。此操作失败的原因是对 IID 为“{00020970-
HRESULT:0x80030002 无法将类型为“Microsoft.Office.Interop.Word.ApplicationClass”的 COM 对象强制转换为接口类型“Microsoft ...
- [一] java8 函数式编程入门 什么是函数式编程 函数接口概念 流和收集器基本概念
本文是针对于java8引入函数式编程概念以及stream流相关的一些简单介绍 什么是函数式编程? java程序员第一反应可能会理解成类的成员方法一类的东西 此处并不是这个含义,更接近是数学上的 ...
- Go基础系列:接口类型断言和type-switch
接口类型探测:类型断言 接口实例中存储了实现接口的类型实例,类型的实例有两种:值类型实例和指针类型实例.在程序运行过程中,接口实例存储的实例类型可能会动态改变.例如: // ins是接口实例 var ...
- 添加 node mocha 测试模块
1.mocha 支持TDD 和 BDD两种测试风格 2.引用assert模块 此模块是node的原生模块,实现断言的功能,作用是声明预期的结果必须满足 3.mocha测试用例中可以使用第三方测试库 ...
- mocha测试框架-truffle
https://mochajs.org/ 学习网址: https://www.jianshu.com/p/9c78548caffa https://www.jb51.net/article/10646 ...
- jmeter中测试接口
本文主要介绍在jmeter中测试接口:主要从以下几个方面进行说明: 1.jmeter简介 2.jmeter怎么做接口测试 3.jmeter进行参数化的几种形式 4.jmeter中处理乱码方法 5.jm ...
- postman工具测试接口
本篇文章主要介绍怎么在postman工具中进行接口的测试? 从以下几个方面进行介绍: 1.先介绍下接口测试 2.不同类型的接口请求方式如何在postman中进行测试 1.1 接口 什么是接口? 接口一 ...
随机推荐
- NoHttpResponseException
采用JMeter2.13做Http性能测试时,在高并发请求的情况下,服务器端并无异常,但是Jmeter端报错NoHttpResponseException (the target server fai ...
- makedepend: command not found(转)
makedepend: command not found 解决方案: 修改Makefile MAKEDEPEND=$(CC) -M 参考: When I set CROSS_COMPILE, `MA ...
- 查看Linux系统版本信息(转)
一.查看Linux内核版本命令(两种方法): 1.cat /proc/version [root@S-CentOS home]# cat /proc/version Linux version 2.6 ...
- Spring 中PageHelper分页插件使用
1.增加pagehelper <!-- mybatis pager --> <dependency> <groupId>com.github.pagehelper& ...
- C# 泛型类和泛型方法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- <亲测>CentOS 7.3下Node.js 8.6安装配置(含NPM以及PM2)
CentOS 7.3下Node.js 8.6安装配置 2017年09月30日 14:12:02 阅读数:2245更多 个人分类: Nodejs 版权声明:本文为博主原创文章,未经博主允许不得转载. ...
- Selenium2+python自动化43-判断title(title_is)
From: https://www.cnblogs.com/yoyoketang/p/6539117.html 前言 获取页面title的方法可以直接用driver.title获取到,然后也可以把获取 ...
- 关于Dubbo面试问题
一.默认使用的是什么通信框架,还有别的选择吗? 默认也推荐使用netty框架,还有mina. 二.服务调用是阻塞的吗? 默认是阻塞的,可以异步调用,没有返回值的可以这么做. 三.一般使用什么注册中心? ...
- Netty Tutorial Part 1.5: On Channel Handlers and Channel Options [z]
Intro: After some feedback on Part 1, and being prompted by some stackoverflow questions, I want to ...
- bzoj4937: [Ceoi2016]popeala
Description 你办了一场比赛,有n给人参加,只有一道题,有m个数据点,标号为1~m,每个测试点都有一个分数a[i].现在所 有选手已经提交了程序并且测评完了,你知道每个人都能通过哪些测试点. ...