2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  We write **unit tests** to explore and confirm the **behavior** of parts of our application.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  我们编写**单元测试**来探索并巩固应用程序中的**行为**部分。
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. They **guard** against breaking existing code (“regressions”) when we make changes.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. 当我们做出修改时,它们会**守护**已有代码(回归测试),防止其被破坏。
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. They **clarify** what  the code does both when used as intended and when faced with deviant conditions.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. 当我们正确使用代码和面对异常情况时,它们会让代码的用途更加**明晰**。
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -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-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. 它们会**揭露**我们设计和实现中的错误。测试会强迫我们从多种角度看代码。如果应用程序的一个部分看起来很难测试,这可能就意味着存在设计缺陷。
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								     我们可以立即修复它,而不用等到它变得不可收拾的那一天。
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								a(id="top")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  # Table of Contents
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  # 目录
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. [Jasmine Testing 101](#jasmine-101)
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. [Jasmine测试简介](#jasmine-101)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-04-20 20:07:39 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - setup to run Jasmine tests in the browser
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								    - 设置浏览器,  来运行Jasmine测试
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-04-20 20:07:39 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - basic Jasmine testing skills
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - Jasmine测试的基本技能
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-04-20 20:07:39 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - write simple Jasmine tests in TypeScript
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 用TypeScript编写简单的Jasmine测试
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-04-20 20:07:39 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - debug a test in the browser
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 在浏览器里调试一个测试
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. [The Application Under Test](#aut)
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. [被测试的应用程序](#aut)
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-24 19:30:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. [First app test](#first-app-tests)
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. [第一个应用程序测试](#first-app-tests)
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-04-20 20:07:39 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - test a simple application interface outside of Angular
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								    - 在Angular之外,  测试一个简单的应用程序接口
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-04-20 20:07:39 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - where to put the test file
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 测试文件存放到哪儿
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-04-20 20:07:39 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - load a test file with systemJS
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 使用systemJS调用一个测试文件
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-24 19:30:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. [Pipe driven development](#pipe-testing)
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. [测试驱动开发一个管道](#pipe-testing)
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-04-20 20:07:39 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - create a test before creating a class
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 创建类之前,先创建一个测试
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-04-20 20:07:39 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - load multiple test files in our test harness, using system.js
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								    - 使用system.js,  往我们的测试套件里加载多个测试文件
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-04-20 20:07:39 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - add the Angular 2 library to our test harness
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 往我们的测试套件里添加Angular 2的类库
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-04-20 20:07:39 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - watch the new test fail, and fix it
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 看着新测试失败,然后修复它
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. Test an Asynchronous Service (forthcoming)
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. 测试异步服务(即将到来)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - test an asynchronous service class outside of Angular
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 在Angular外测试异步服务类
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - write a test plan in code
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 用代码写测试计划
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - fake a dependency
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 伪造一个依赖
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - master the `catch(fail).then(done)` pattern
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 掌握`catch(fail).then(done)`模式
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - move setup to `beforeEach`
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 把设置工作移入`beforeEach`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - test when a dependency fails
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 测试依赖失败时的情况
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - control async test timeout
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 控制异步测试的超时时间
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. The Angular Test Environment (forthcoming)
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								  1. Angular测试环境(  即将到来) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - the Angular test environment and why we need help
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - Angular测试环境以及我们为什么需要它的帮助
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - add the Angular Test libraries to the  test harness
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 把Angular测试库加入测试挽具中
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - test the same async service using Angular Dependency Injection
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 使用Angular依赖注入测试同一个异步服务
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - reduce friction with test helpers
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 减少与测试助手的摩擦
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - introducing spies
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 引入侦探类
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. Test a Component (forthcoming)
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. 测试组件(即将到来)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - test the component outside of Angular
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 在Angular外面测试组件
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - mock the dependent asynchronous service
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 模拟所依赖的异步服务
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - simulate interaction with the view (no DOM)
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								    - 仿真与视图的交互(  不涉及DOM) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - use a spy-promise to control asynchronous test flow
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 使用侦探型承诺(spy-promise)来控制异步测试工作流
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. Test a Component in the DOM (forthcoming
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								  1. 在DOM中测试组件(  即将到来) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - test the component inside the Angular test environment
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 在Angular测试环境中测试组件
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - use the `TestComponentBuilder`
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 使用`TestComponentBuilder`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - more test helpers
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 更多测试助手
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - interact with the DOM
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 与DOM交互
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - bind to a mock dependent asynchronous service
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    - 绑定到一个模拟的异步服务
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  1. Run the tests with karma (forthcoming)
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								  1. 用Karma运行测试(  即将到来) 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								  It’  s a big agenda. Fortunately, you can learn a little bit at a time and put each lesson to use.
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  这是一个很大的日程表。幸运的是,我们可以一次只学一小点,然后把它们投入实战。
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								a(href="#top").to-top Back to top
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								.l-hr
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								a(id="jasmine-101")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  # Jasmine Testing 101
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  # Jasmine测试简介
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								!= partial("../testing/jasmine-testing-101")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								a(href="#top").to-top Back to top
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								a(href="#top").to-top 回到顶部
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								.l-hr
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								a(id="aut")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  # The Application to Test
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  # 被测试的应用程序
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								!= partial("../testing/application-under-test")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								a(href="#top").to-top Back to top
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								a(href="#top").to-top 回到顶部
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								.l-hr
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								a(id="first-app-tests")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-03-24 19:30:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  # First app test
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  # 第一个应用程序测试
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								!= partial("../testing/first-app-tests")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								a(href="#top").to-top Back to top
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								a(href="#top").to-top 回到顶部
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								.l-hr
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								a(id="pipe-testing")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-03-24 19:30:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  # Pipe driven development
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  # 测试驱动开发一个管道
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								!= partial("../testing/testing-an-angular-pipe")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								a(href="#top").to-top Back to top
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								a(href="#top").to-top 回到顶部
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								.alert.is-important
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    The testing chapter is still under development.
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 14:07:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    Please bear with us as we both update and complete it.
							 
						 
					
						
							
								
									
										
										
										
											2016-05-31 12:35:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    测试章节正在开发中,请耐心,我们会更新并完成它。