198 lines
5.2 KiB
Plaintext
Raw Normal View History

:marked
We write **unit tests** to explore and confirm the **behavior** of parts of our application.
2016-05-30 08:54:35 +08:00
2016-05-30 09:22:20 +08:00
我们编写**单元测试**来探索并巩固应用程序中的**行为**部分。
2016-05-30 08:54:35 +08:00
1. They **guard** against breaking existing code (“regressions”) when we make changes.
2016-05-30 08:54:35 +08:00
2016-05-30 09:22:20 +08:00
1. 当我们做出修改时,它们会**守护**已有代码,防止其被破坏。
2016-05-30 08:54:35 +08:00
1. They **clarify** what the code does both when used as intended and when faced with deviant conditions.
2016-05-30 08:54:35 +08:00
2016-05-30 09:22:20 +08:00
1. 当我们正确使用代码和面对异常情况时,它们会让代码的用途更加**明晰**。
2016-05-30 08:54:35 +08:00
1. They **reveal** mistakes in design and implementation. Tests force us to look at our code from many angles. When a part of our application seems hard to test,
we may have discovered a design flaw, something we can cure now rather than later when it becomes expensive to fix.
2016-05-30 08:54:35 +08:00
2016-05-30 09:22:20 +08:00
1. 它们会**揭露**我们设计和实现中的错误。测试会强迫我们从多种角度看代码。如果应用程序的一个部分看起来很难测试,这可能就意味着存在设计缺陷。
我们可以立即修复它,而不用等到它变得不可收拾的那一天。
.alert.is-important
:marked
These testing chapters were written before the Angular 2 Beta release
and are scheduled for significant updates.
Much of the material remains accurate and relevant but references to
specific features of Angular 2 and the Angular 2 testing library
may not be correct. Please bear with us.
2016-05-30 08:54:35 +08:00
2016-05-30 09:22:20 +08:00
这些关于测试的章节写于Angular 2 Beta版发布之前并且已经准备做重大更新。
这些素材中很多都是准确而有意义的但是所引用的Angular 2特有特性和测试库可能是不正确的。各位见谅。
:marked
Here is what well learn in the unit testing chapters.
2016-05-30 09:22:20 +08:00
下面是我们将在单元测试一章中学到的:
1. Jasmine Testing 101
2016-05-30 09:22:20 +08:00
1. Jasmine测试简介
2016-05-30 09:22:20 +08:00
- setup to run Jasmine tests in the browser
2016-05-30 09:22:20 +08:00
- 在浏览器中设置并准备运行Jasmine测试
- basic Jasmine testing skills
2016-05-30 09:22:20 +08:00
- 基本的Jasmine测试技能
- write simple Jasmine tests in TypeScript
2016-05-30 09:22:20 +08:00
- 用TypeScript写一个简单的Jasmine测试
- debug a test in the browser
2016-05-30 09:22:20 +08:00
- 在浏览器中调试一个测试
1. The Application Under Test
2016-05-30 08:54:35 +08:00
2016-05-30 16:39:21 +08:00
1. 待测试的应用程序
2016-05-30 09:22:20 +08:00
1. Test a class
2016-05-30 09:22:20 +08:00
1. 测试一个类
- test a simple application class outside of Angular
2016-05-30 09:22:20 +08:00
- 在Angular测试环境外测试简单的应用类
- where to put the test file
2016-05-30 09:22:20 +08:00
- 把测试文件放在哪里
- load a test file with systemJS
2016-05-30 09:22:20 +08:00
- 用SystemJS加载测试文件
1. Test a Pipe
2016-05-30 09:22:20 +08:00
1. 测试一个管道
- test a simple Angular Pipe class
2016-05-30 09:22:20 +08:00
- 测试一个简单的Angular管道类
- add the Angular 2 library to the test harness
2016-05-30 09:22:20 +08:00
- 把Angualr 2库添加到测试挽具(harness)中
- load multiple test files using system.js
2016-05-30 09:22:20 +08:00
- 使用SystemJS加载多个测试文件
1. Test an Asynchronous Service
2016-05-30 09:22:20 +08:00
1. 测试异步服务
- test an asynchronous service class outside of Angular
2016-05-30 09:22:20 +08:00
- 在Angular测试环境外测试异步服务
- write a test plan in code
2016-05-30 09:22:20 +08:00
- 用代码写一个测试计划
- fake a dependency
2016-05-30 09:22:20 +08:00
- 伪造一个依赖
- master the `catch(fail).then(done)` pattern
2016-05-30 09:22:20 +08:00
- 掌握`catch(fail).then(done)`模式
- move setup to `beforeEach`
2016-05-30 09:22:20 +08:00
- 把设置代码移入`beforeEach`
- test when a dependency fails
2016-05-30 09:22:20 +08:00
- 测试依赖失败时的情况
- control async test timeout
2016-05-30 09:22:20 +08:00
- 控制异步测试的超时时间
1. The Angular Test Environment
2016-05-30 09:22:20 +08:00
1. Angular测试环境
- the Angular test environment and why we need help
2016-05-30 09:22:20 +08:00
- Angular测试环境以及我们为什么需要它的帮助
- add the Angular Test libraries to the test harness
2016-05-30 09:22:20 +08:00
- 把Angular测试库加入测试挽具中
- test the same async service using Angular Dependency Injection
2016-05-30 09:22:20 +08:00
- 用Angular依赖注入测试同一个异步服务
- reduce friction with test helpers
2016-05-30 09:22:20 +08:00
- 减少和测试助手的摩擦
- introducing spies
2016-05-30 09:22:20 +08:00
- 引入侦探类
1. Test a Component
2016-05-30 09:22:20 +08:00
1. 测试组件
- test the component outside of Angular
- 在Angular测试环境外测试组件
- mock the dependent asynchronous service
2016-05-30 09:22:20 +08:00
- 模拟所依赖的异步服务
- simulate interaction with the view (no DOM)
2016-05-30 09:22:20 +08:00
- 仿真和视图(没有DOM)的互动
- use a spy-promise to control asynchronous test flow
2016-05-30 09:22:20 +08:00
- 使用侦探型承诺(spy-promise)来控制异步测试工作流
1. Test a Component in the DOM
2016-05-30 09:22:20 +08:00
1. 在DOM中测试组件
- test the component inside the Angular test environment
2016-05-30 09:22:20 +08:00
- 在Angular测试环境中测试组件
- use the `TestComponentBuilder`
2016-05-30 09:22:20 +08:00
- 使用`TestComponentBuilder`
- more test helpers
2016-05-30 09:22:20 +08:00
- 更多测试助手
- interact with the DOM
2016-05-30 09:22:20 +08:00
- 与DOM互动
- bind to a mock dependent asynchronous service
2016-05-30 09:22:20 +08:00
- 绑定到一个模拟的被依赖异步服务
1. Run the tests with karma
2016-05-30 09:22:20 +08:00
1. 用Karma运行这些测试
Its a big agenda. Fortunately, you can learn a little bit at a time and put each lesson to use.
2016-05-30 09:22:20 +08:00
这是一个很大的日程表。幸运的是,我们可以一次只学一小点,然后把它们投入实战。