127 lines
4.7 KiB
Plaintext
127 lines
4.7 KiB
Plaintext
:marked
|
||
We write **unit tests** to explore and confirm the **behavior** of parts of our application.
|
||
|
||
我们编写**单元测试**来探索和确认我们应用程序的**行为**部分。
|
||
|
||
1. They **guard** against breaking existing code (“regressions”) when we make changes.
|
||
1. 当我们改变代码是,它们**守护**已有代码,以防被破坏。
|
||
|
||
1. They **clarify** what the code does both when used as intended and when faced with deviant conditions.
|
||
1. 在我们正确使用代码和面对异常情况时,它们**澄清**代码做什么。
|
||
|
||
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.
|
||
1. 它们**揭示**我们设计和实现的错误。测试强迫我们从多个角度看代码。当应用程序的一个部分看起来很难测试,我们可能会发现设计缺陷,这是我们可以立刻修复的,而不是等到它变得很难修复的时候。
|
||
|
||
a(id="top")
|
||
:marked
|
||
# Table of Contents
|
||
# 目录
|
||
1. [Jasmine Testing 101](#jasmine-101)
|
||
1. [Jasmine测试101](#jasmine-101)
|
||
- setup to run Jasmine tests in the browser
|
||
- 设置浏览器来运行Jasmine测试
|
||
- basic Jasmine testing skills
|
||
- 基础Jasmine测试技能
|
||
- write simple Jasmine tests in TypeScript
|
||
- 实用TypeScript来编写简单的Jasmine测试
|
||
- debug a test in the browser
|
||
- 在浏览器里调试测试
|
||
|
||
1. [The Application Under Test](#aut)
|
||
|
||
1. [被测试的应用程序](#aut)
|
||
|
||
1. [First app test](#first-app-tests)
|
||
1. [第一个应用程序测试](#first-app-tests)
|
||
- test a simple application interface outside of Angular
|
||
- 在Angular之外,测试一个简单的应用程序接口
|
||
- where to put the test file
|
||
- 测试文件存放到哪儿
|
||
- load a test file with systemJS
|
||
- 使用systemJS调用一个测试文件
|
||
|
||
1. [Pipe driven development](#pipe-testing)
|
||
1. [测试驱动开发一个管道](#pipe-testing)
|
||
- create a test before creating a class
|
||
- 在新建类之前,新建一个测试
|
||
- load multiple test files in our test harness, using system.js
|
||
- 使用system.js,加载多个测试文件到我们的测试套装里
|
||
- add the Angular 2 library to our test harness
|
||
- 添加Angular 2的类库到我们的测试套装里
|
||
- watch the new test fail, and fix it
|
||
- 看着新测试失败,然后修复它
|
||
|
||
1. Test an Asynchronous Service (forthcoming)
|
||
- test an asynchronous service class outside of Angular
|
||
- write a test plan in code
|
||
- fake a dependency
|
||
- master the `catch(fail).then(done)` pattern
|
||
- move setup to `beforeEach`
|
||
- test when a dependency fails
|
||
- control async test timeout
|
||
|
||
1. The Angular Test Environment (forthcoming)
|
||
- the Angular test environment and why we need help
|
||
- add the Angular Test libraries to the test harness
|
||
- test the same async service using Angular Dependency Injection
|
||
- reduce friction with test helpers
|
||
- introducing spies
|
||
|
||
1. Test a Component (forthcoming)
|
||
- test the component outside of Angular
|
||
- mock the dependent asynchronous service
|
||
- simulate interaction with the view (no DOM)
|
||
- use a spy-promise to control asynchronous test flow
|
||
|
||
1. Test a Component in the DOM (forthcoming
|
||
- test the component inside the Angular test environment
|
||
- use the `TestComponentBuilder`
|
||
- more test helpers
|
||
- interact with the DOM
|
||
- bind to a mock dependent asynchronous service
|
||
|
||
1. Run the tests with karma (forthcoming)
|
||
|
||
It’s a big agenda. Fortunately, you can learn a little bit at a time and put each lesson to use.
|
||
|
||
a(href="#top").to-top Back to top
|
||
|
||
.l-hr
|
||
a(id="jasmine-101")
|
||
:marked
|
||
# Jasmine Testing 101
|
||
# Jasmine测试101
|
||
!= partial("../testing/jasmine-testing-101")
|
||
a(href="#top").to-top Back to top
|
||
|
||
.l-hr
|
||
a(id="aut")
|
||
:marked
|
||
# The Application to Test
|
||
# 被测试的应用程序
|
||
!= partial("../testing/application-under-test")
|
||
a(href="#top").to-top Back to top
|
||
|
||
.l-hr
|
||
a(id="first-app-tests")
|
||
:marked
|
||
# First app test
|
||
# 第一个应用程序测试
|
||
!= partial("../testing/first-app-tests")
|
||
a(href="#top").to-top Back to top
|
||
|
||
.l-hr
|
||
a(id="pipe-testing")
|
||
:marked
|
||
# Pipe driven development
|
||
# 测试驱动开发一个管道
|
||
!= partial("../testing/testing-an-angular-pipe")
|
||
a(href="#top").to-top Back to top
|
||
|
||
.alert.is-important
|
||
:marked
|
||
The testing chapter is still under development.
|
||
Please bear with us as we both update and complete it.
|
||
|
||
测试章节正在开发中,请耐心,我们会更新并完成它。
|