(Source Code: https://github.com/testfoxx/TwoFlashLight.git)
先從程式碼的層面一步步開始重構吧,首先是 package 和 class 的名稱沒有符合 coding standard。
格式良好的 coding standard 會讓 code 看起來更簡潔更有規範,相對提高了可讀性。
 

Rename package

觀察 com/tylerfoxx/twoflash 中的 class , 其中 MainActivity 會被當作起始點啟動,所以先暫時把 package name 改為含有主要(main)的名稱。
之後重構分離 class 可以再建立其他的package 放入 class 也沒關係。將 package name 從 com/tylerfoxx/twoflash 改為 com/twoflashlight/main
觀察 FoXxLib 中的 class,發現 class 負責的工作似乎都不相關,看起來並沒有一定的關聯性,所以先改名為 utility 名稱。
將 package name 從 FoXxLib 改為 com/twoflashlight/utility。
完成修改後可先在 local 端啟動 UnitTest,避免讓本次重構產生其他的bug,確定 UnitTest 過關之後再 git merge 到遠端 Server (github)。
本地端啟動UnitTest的步驟為:
Step 1. 開啟終端機到TwoFlashLight/Two_FlashLight/test
Step 2. 確認已經有裝置連線後輸入 ant clean emma debug install test
Step 3. 最後在終端機會顯示這次的UnitTest狀態,如下

test:
[getlibpath] Library dependencies:
[getlibpath] No Libraries
     [echo] Running tests...
     [echo] Running tests ...
     [exec]
     [exec] com.twoflashlight.test.UnitTest:.
     [exec] Test results for InstrumentationTestRunner=.
     [exec] Time: 7.372
     [exec]
     [exec] OK (1 test)
     [exec]
     [exec]
...

結果代表本次的 UnitTest 成功通過。UnitTest 的類別位於 src/com/twoflashlight/test/UnitTest.java。
測試內容相當簡單,啟動MainActivity並測試其不為空值(null)。
當然,若重構的過程有修改到其他部份,也必須增加到 UnitTest 才行。
local 端測試 UnitTest 並成功通過後就可 git push 到遠端 Server上,再到 github 手動 merge 本次修改,每次完成 merge,jenkins 都會自動 build project。
除了即時通知本次的 merge 會不會造成 build fail , 也可以使用套件分析程式碼以了解專案的狀態。