Jasmine

Preview:

DESCRIPTION

jasmine入门介绍,by苏河

Citation preview

苏河

• 界面老是改,测毛线

• 都是业务代码,测毛线

• 项目时间太紧,测毛线

• 测毛线,还是目测给力……

• RIA

• Base on Browser

• Heavy Javascript

• Html 5

产品的变化

Server Browser

Server Browser

开发量的变化

前端质量

内部质量

可维护性性能设计模式开发效率

外部质量

功能

界面

前端关注点的变化

困难重重

• 浪费太多时间

• 效率太低,意义不大

• 从没写过 javascript 的单元测试

How?

Jasmine• Jasmine 是一个 BDD 的javascript 单元测试框架

Jasmine• 语法简单

• 代码易读性

• 不依赖其他 js 框架

• 敏捷

• Nodejs 、 ruby 、 java 、 html

Specs

Expectations

Suites

Nested Describes

Disabling Tests & Suites

Matchers

Your matchers

Before and After

Spies matchers

• expect(x).toHaveBeenCalled();• expect(x).toHaveBeenCalledWith(arguments);• expect(x).not.toHaveBeenCalled();• expect(x).not.toHaveBeenCalledWith(argume

nts);

Spies

• spyOn(x, 'method').andCallThrough();• spyOn(x, 'method').andReturn(arguments);• spyOn(x, 'method').andThrow(exception);• spyOn(x, 'method').andCallFake(function);• spyOn(x, 'method').andReturn(value1); ... ;

x.method.andReturn(value2);

spies

Asynchronous specs

waits

waitsFor

• waitsFor(function, optional message, optional timeout)

爱逛街 demo

• 是否有问题?

预告片

• 如何更好的架构可测试代码

• 如何集成到 klude 测试平台

• ……

QA