Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Android應用程式開發
ezScrum團隊
Who am I ?OPH
ezScrum團隊的成員
Certified Scrummaster 2010
Agenda持續整合?
開發經驗背景
Continuous Integration環境架設
持續整合?
ContinuousContinuousIntegration?
Compile ->手動執行就好?
手動執行不是就可以了嗎?
Compile ->手動執行就好?測試 ->手動執行就好?靜態分析 ->手動執行就好?部屬 ->手動執行就好?產生報表給老闆 ->手動執行就好?
麻煩、懶
寫程式都來不寫程式都來不及了!!!
工讀生來做?
主管:主管:請共體時艱
持續整合系統
只需要付電費只需要付電費
Continuous IntegrationIntegration有什麼好處?
有問題立刻會知道
成就感!
成就感!
芒刺在背…
有CI系統 !=
有好的品質有好的品質
在我們多次爛掉使用經驗中
沒人看 = 沒用!
怎樣讓持續整合持續整合活下去?
讓你的團隊想關心他!
我們是用Scrum
»2010.12.27 ~ 2011.02.25 (8週)
»一個五人的團隊
»分成5個Sprint
Sprint 1 Sprint 2 Sprint 3 Sprint 4 Sprint 5
週數 2周 2周 1周 2周 1周
»Android 手機:
˃i9000
˃HTC Magic
˃G1
»持續整合系統:
˃Jenkins
»版本控管系統
˃Mecurial
工作環境
工作環境
項目 數量
Classes 143
專案的規模…
Functions 635
程式碼行數 4250
何時執行建置?
版本新增版本新增每天0點
開發過程中
有好心人士有有好心人士有事沒事看一下
Daily Scrum前
確認確認有沒有錯誤
Sprint Review
給客戶看專案給客戶看專案目前的狀況
登入就可以看到專案狀況
用CheckStyle檢查程式碼規範
用Findbugs找尋潛在可能的錯誤
JavaNCSS分析程式碼規模
使用Android預設的架構建立一個測試專案
除了JUnit還有分析CodeCoverage
發現有錯誤時?
互相幹譙討論互相幹譙討論立刻修!
誰要修復錯誤?
誰Commit誰修誰Commit誰修好心小精靈
用Robotium
做黑箱測試做黑箱測試
用內建的Monkey TestMonkey Test
ContinuousIntegration
環境架設篇
Open Source
讓Jenkins替Android服務
要怎樣讓Jenkins懂得用Jenkins懂得用Android?
Apache Ant
Jenkins懂Jenkins懂Android也懂我也略懂略懂…
注意!!
最好用Ant 1.8最好用Ant 1.8以上的版本不然小綠人會拉肚子
先感謝布蘭登
建立主專案一般專案:
建立新專案:android create project android create project --target <target_ID>--name <your_project_name>--path <path_to_your_project>--activity <your_activity_name>--package <your_package_namespace>
建立測試專案測試專案
建立新的測試專案android create test-project android create test-project –m <main_path>-n <project_name>-p <test_path>
如果已經用Eclipse建立好專案的話?
更新專案android update project--name <project_name>--name <project_name>--target <target_ID>--path <path_to_your_project>
測試專案android update test-project –m <main_path>-p <test_path>
一般專案的Ant更新主專案android update project--name <project_name>--target <target_ID>--target <target_ID>--path <path_to_your_project>
測試專案android update test-project –m <main_path>-p <test_path>
產生的檔案可以做啥?build.xml
他就是你的buildfile
local.properties 不要加入版本控管local.properties紀錄開發端屬性的檔案
build.propertiesAnt執行Build時候所讀取的屬性檔
default.propertiesAndroid啟動時所需要讀取的屬性檔
不要加入版本控管
版本控管的ignore範例.settings/bin/syntax:regexp^local\.properties$^local\.properties$syntax:regexp^doc$syntax:regexp^gen/cz/romario/opensudoku/R\.java$
Buildfile
裡面寫了什麼?裡面寫了什麼?
其實沒什麼因為Android SDK裡面有寫好了
<?xml version="1.0" encoding="UTF-8"?><project name="OpenSudoku" default="help">
<property file="local.properties" />好了<property file="build.properties" />
<property file="default.properties" />
<path id="android.antlibs"><pathelement path="${sdk.dir}/tools/lib/anttasks.jar" /><pathelement path="${sdk.dir}/tools/lib/sdklib.jar" /><pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" />
</path>
<taskdef name="setup"classname="com.android.ant.SetupTask"classpathref="android.antlibs" />
<setup />
</project>
注意!!taskdef與property定義在<setup/>前義在<setup/>前
target定義在<setup/>後
主專案的BuildfileBuildfile要寫什麼?
CompileFindbugsCheckStyleCheckStyleJavaNCSS
Findbugs
用Bug Patters的概念找出開發人員比較有意找出開發人員比較有意願去修復的Bug
<path id="findbugs_lib">
<fileset dir="${findbugs.home}/lib/">
<include name="*.jar" />
</fileset>
</path>
在<Setup/>之前
</path>
<taskdef name="findbugs"
classname="edu.umd.cs.findbugs.anttask.FindBugsTask"
classpathref="findbugs_lib" />
<target name="findbugs" depends="compile">
<findbugs home="${findbugs.home}"
excludefilter="FindBugConfig.xml"
output="xml:withMessages" outputFile="findbugs.xml"
jvmargs="-Xss1m -Xmx800m">
在<Setup/>之後
jvmargs="-Xss1m -Xmx800m">
<sourcePath path="src" />
<auxClasspath path="${android.jar}" />
<class location="${out.dir}" />
</findbugs>
</target>
Findbugs的設定檔<FindBugsFilter>
<Match>
<Class name="~.*\.R\$.*" />
<Bug pattern=
"NM_CLASS_NAMING_CONVENTION" />"NM_CLASS_NAMING_CONVENTION" />
</Match>
</FindBugsFilter>
不設的話會看到Findbugs找到R.java裡面有一堆Bug,會很不開心
CheckStyle
檢查程式碼規範檢查程式碼規範
<taskdef
resource="checkstyletask.properties"
classpath="${checkstyle.home}/checkstyle-
在<Setup/>之前
classpath="${checkstyle.home}/checkstyle-
5.3-all.jar" />
<target name="checkstyle“ description="Generates a
report of code convention violations.">
<checkstyle config="checkStyle_rule.xml"
failureProperty="checkstyle.failure"
failOnViolation="false">
在<Setup/>之後
failOnViolation="false">
<formatter type="xml" tofile="checkstyle_report.xml" />
<fileset dir="src" includes="**/*.java" />
</checkstyle>
</target>
JavaNCSS
計算程式碼的行數與複雜度與複雜度
<path id="javancss_lib"><fileset dir="${javancss.home}/lib/"><include name="*.jar" />
在<Setup/>之前
<include name="*.jar" /></fileset></path><taskdef name="javancss" classname="javancss.JavancssAntTask" classpathref="javancss_lib" />
<target name="javancss"><javancss srcdir="src" generateReport="true" outputfile="javancss_metrics.xml" format="xml" /><xslt in="javancss_metrics.xml" out="javancss-
在<Setup/>之後
<xslt in="javancss_metrics.xml" out="javancss-metrics.html" style="${ javancss.home}/xslt/javancss2methodhtml.xsl" /></target>
測試專案的BuildfileBuildfile要寫什麼?
Junit
EmmaEmma
buildfile主專案=測試專案
測試專案多設定build.properties
但測試的結果在模擬器或手機裡面
替換TestRunner替換TestRunner將測試報告複製出來
感謝Jsankey
https://github.comhttps://github.com
/jsankey
/android-junit-report
替換TestRunner
android-junit-report-1.2.6->測試專案的libs資料夾中->測試專案的libs資料夾中
修改AndroidManifest.xml的<instrumentation ... />android.test.InstrumentationTestRunnerandroid.test.InstrumentationTestRunner修改為
com.zutubi.android.junitreport.JUnitReportTestRunner
增加測試target<target name="fetch-test-report"><echo>Downloading XML test report...</echo>
<mkdir dir="${reports.dir}"/><exec executable="${adb}" failonerror="true"><arg line="${adb.device.arg}"/><arg value="pull" /><arg value="pull" /><arg
value="/data/data/${manifest.package}/files/junit-report.xml" />
<arg value="${reports.dir}/junit-report.xml" /></exec></target>
Emma需要重新設定
no metadata found in any of the data files
因為.em與.ec檔案沒有放在一起
.em檔案是從主專案產生的
改變主專案target-emma-instrument
自行設定.em檔的產生路徑
參考http://blog.appmakr
.com/android-code-.com/android-code-
coverage/
安裝設定Jenkins
下載Jenkinshttp://jenkins-ci.org/
Windows可能會遇到的問題
若用自動安裝,
Jenkins會設定以Windows Service
的方式自動啟動
修改Service權限
若用自動安裝,
Jenkins會設定以Windows Service
的方式自動啟動
安裝Plugin1. Android Emulator Plugin2. Checkstyle Plug-in3. Jenkins Emma Plugin3. Jenkins Emma Plugin4. FindBugs Plug-in5. Jenkins JavaNCSS Plugin6. Junit Attachments Plugin
Jenkins設定
Android SDK路徑設定
在Jenkins上設定主專案
在Jenkins上設定測試專案
夢想
可以同時在多台可以同時在多台手機上進行
http://forum.scrum.tw/