做者第一次项目失败的缘由:编写的测试过于脆弱, 名字不够清楚,还有的测试互相依赖。html
单元测试是代码(一般是方法),它调用其余代码,检验假定的正确性。若是假定错误的,单元测试失败,反之成功。
SUT system under test,被测系统,也有 CUT(class under test or code under test)的说法。java
单元调用系统公共方法到产生结果之间的部分。结果能够是:返回值(非void)、系统的状态或行为改变、不受控制的第三方系统调用。android
单元测试的范围能够小到一个方法,大到多个类。git
好的单元测试:
自动化,可重复执行;
很容易实现;
长久性;
一键运行;
运行速度很快;
结果应该是稳定;
能彻底控制被测单元;
彻底隔离;
失败时的信息能帮助问题定位。github
任何测试,若是它运行速度不快,结果不稳定,或者要用到被测试单元的真实依赖(时间、网络、数据库、线程或随机数产生器),就认为它是集成测试。数据库
测试驱动开发:http://osherove.com/blog/2007/10/8/the-various-meanings-of-tdd.htmlapache
调试时间是多少、定位bug时间、从新验证代码正确性。
assertEquals的精度。
自定义断言,暂不涉及。编程
至67页。网络
真实对象属性具备不可肯定的行为(产生不可预测的结果、如股票行情)。
真实对象很难被建立(好比支付接口)
真实对象运行速度很慢
真实对象涉及用户界面
测试须要询问真实对象是如何被调用的(好比验证回调函数的调用)
真实对象还未就绪并发
使用接口描述对象
实现接口
mock中实现接口
好的测试 A-TRIP
自动化Automatic: 调用测试自动化和检查结果自动化。
完全的Thorough: 注意BUG群集现象
可重复的Repeatable:
独立的Independent
专业的Professional: 像开发同样写测试代码。
修正bug时改进测试、引入bug证实测试,好比TDD。
1,Android Studio简介
安装JDK
仿真(emulation)比模拟(simulation)更接近真实。x86_64的仿真须要硬件加速,没有硬件加速的请使用armeabi。建立虚拟机的参考:http://phonearena.com/。其余推荐Genymotion。
连手机的USB驱动能够参考:developer.android.com/tools/extras/oem-usb.html#Drivers。可能须要adb start-server,驱动也可能要重启才能生效。
2,浏览Android Studio
切换TAB: Alt+Right-Arrow | Ctrl+Right-Arrow 或 Alt+Left-Arrow | Ctrl+Left-Arrow keys
Marker Bar: 告警、编译错误、未提交内容、查找结果、书签位置。
Project Tool Window三种模式: Project, Packages和Android,默认为Android。Android和Project比较经常使用,Android会隐藏一些目录。右键点击菜单的重要选项:Copy Path, File Path及Show in Explorer。
Structure Tool Window:用于文件内导航。
Favorites Tool Window:逻辑分组文件。F11 (F3 on Mac)建立的书签和单击gutter建立的断点也在这里。
TODO Tool Window:
Commander Tool Window
The Main Menu Bar
The Toolbar
The Navigation Bar
The Status Bar:
点击Toggle Margins button隐藏边框,移动到上面显示上下文菜单。
message area显示并发执行信息,单击 message area打开事件。
Editor cursor position:显示行列数,单击能够指定要去的行和列。
line separator area:换行格式,Git会自动转换CRLF为LF。单击能够选择。
text format area:编码格式,单击能够选择。
file access indicator area: 单击能够选择文件写权限。
The Highlighting Level:点击高亮模式。默认为Inspections,关注错误和告警。其余选项有Syntax和None。
通用操做:
Selecting Text:双击、左键拖拉、Shift+Down-Arrow或Shift+Up-Arrow、三次左键选择行,Ctrl+A | Cmd+A、Ctrl+W | Alt+Up-Arrow选择整个单词。
Undo and Redo:Ctrl+Z| Cmd+Z and Ctrl+Shift+Z | Cmd+Shift+Z,记录300次。
Finding Recent Files:View ➤ Recent Files或Ctrl+E | Cmd+E。默认50个,能够在 File ➤ Settings ➤ Limits ➤ Editor ➤ Recent Files Limit设定。
Traversing Recent Navigation Operations: Ctrl+Alt+Left-Arrow | Cmd+Alt+Left-Arrow or Ctrl+Alt+Right-Arrow| Cmd+Alt+Right-Arrow。
Cutting, Copying, and Pasting:
Command PC Keys Mac Keys
Cut Ctrl+X Cmd+X
Copy Ctrl+C Cmd+C
Paste Ctrl+V Cmd+V
Extended Paste Ctrl+Shift+V Cmd+Shift+V
Copy Path Ctrl+Shift+C Cmd+Shift+C
Copy Reference Ctrl+Alt+Shift+C Cmd+Alt+Shift+C
至39页末尾。
3,在Android Studio中编程:
查找类:Ctrl+N | Cmd+O
显示行数:Help ➤ Find Action. Type show line numbers
http://im.myoas.com:10703/g1/M00/38/48/rBBmYVcW_FaASS1kAAE2qCbSJUA560.png?w=1306&h=636&s=79528
代码折叠的快捷方式:
展开 Ctrl+加号
折叠 Ctrl+减号
所有展开 Ctrl+Shift+加号
所有折叠 Ctrl+Shift+减号
折叠开关 Ctrl+点
相关配置:Settings ➤ Editor ➤ Code Folding
代码完成:
默认代码完成,输入时自动发生。
基本代码完成,相似于默认代码完成,显示Javadoc窗口
智能型代码,显示Javadoc并提供相关建议。
循环展现 针对已有单词。
Default None 可用上下箭头选择。
Basic Ctrl+Space Ctrl+Space B
SmartType Ctrl+Shift+Space Ctrl+Shift+Space
Cyclic Expand Word(前向) Alt+/ Alt+/
Cyclic Expand Word(后向)Alt+Shift+/ Alt+Shift+?
到50页。
4,代码重构
右键菜单有Refactor选项。能够改变name、Signature、Migration(改变返回的数据类型等)、Move(有三种方法)、Copy、Safe Delete、Extract(Variable、Constant、Field、Parameter、Method)
高级重构:
Push Members Down and Pull Members Up
Replace Inheritance with Delegation
Encapsulate Fields
Wrap Method Return Value
Replace Constructor with Factory Method
Convert Anonymous to Inner
5,Reminders Lab: Part 1
git clone https://bitbucket.org/csgerber/reminders.git
导入git: VCS ➤ Import into Version Control ➤ Create Git Repository
新增文件到git, Ctrl+Alt+A | Cmd+Alt+A 或者右键-> git 添加。
Ctrl+K | Cmd+K 显示提交窗口。
构建UI
插件:( https://wiki.jenkins-ci.org/display/JENKINS/Publish+Over+SSH+Plugin
Maven基于profile区分环境。
https://wiki.jenkins-ci.org/display/JENKINS/Promoted+Builds+Plugin 可用于哪些版本须要测试部测试。
maven构建过程介绍:http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference
建立maven模板( http://Maven.apache.org/guides/introduction/introduction-to-archetypes.html 后者直接建立 pom.xml
绘图插件:( https://wiki.jenkins-ci.org/display/JENKINS/Plot+Plugin https://wiki.jenkins-ci.org/display/JENKINS/
Analysis+Collector+Plugin http://docs.codehaus.org/display/SONAR/Jenkins+Plugin
执行测试的组件: Sloccount plugin ( https://wiki.jenkins-ci.org/display/JENKINS/
SLOCCount+Plugin ) and task scanner plugin ( https://wiki.jenkins-ci.org/
display/JENKINS/Task+Scanner+Plugin ). 前者依赖 static analysis utilities。
环境变量处理:EnvFile
plugin ( https://wiki.jenkins-ci.org/display/JENKINS/Envfile+Plugin )
and the EnvInject plugin ( https://wiki.jenkins-ci.org/display/JENKINS/
EnvInject+Plugin ).
读取属性: ( http://mojo.codehaus.org/properties-
maven-plugin/ ).
JSP编译:( http://www.eclipse.org/jetty/documentation/current/jetty-jspc-
maven-plugin.html
部署:Maven Wagon plugin ( http://mojo.codehaus.org/wagon-maven-plugin/
aptly-named Deploy plugin ( https://wiki.
jenkins-ci.org/display/JENKINS/Deploy+Plugin ).
编程规范参考: http://www.oracle.com/technetwork/java/codeconventions-150003.pdf
汇总报告: https://wiki.jenkins-ci.org/display/JENKINS/Violations
Analysis Collector plugin ( https://wiki.jenkins-ci.org/display/JENKINS/Analysis+Collector+Plugin )
软件度量
https://en.wikibooks.org/wiki/Introduction_to_Software_Engineering/Quality/Metrics
yum -y install sloccount
html: ( https://wiki.jenkins-ci.org/display/JENKINS/Unicorn+Validation+Plugin
( https://wiki.jenkins-ci.org/display/JENKINS/Plot+Plugin
JavaNCSS plugin ( https://wiki.jenkins-ci.org/display/JENKINS/
JavaNCSS+Plugin ).
Sonar plugin ( http://docs.codehaus.org/display/SONAR/
Jenkins+Plugin ).
做者博客:
https://github.com/hltbra
https://github.com/dayvson
审稿; http://blog.jupo.org/