做者第一次項目失敗的緣由:編寫的測試過於脆弱, 名字不夠清楚,還有的測試互相依賴。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/