Windows下Android项目搭建Jenkins持续构建+自动化测试

时间 : 14-09-10 栏目 : Android, CI, 集成测试 作者 : meiw@z3a105.com 评论 : 0 点击 : 301 次

使用持续集成和自动化测试的好处就不说了,网上一搜一大把,不太了解的可以去Google search。下面开始介绍如何在Windows环境下为Android项目搭建Jenkins。本文中使用的版本管理工具是SVN,大部分内容都参考自Jenkins官网,而且本文不考虑SDK Tools 14以下的情况。

安装Jenkins + 建立项目
1,  打开http://jenkins-ci.org/, 下载jenkins.war。
2,  Jenkins的安装非常简单,可以直接在命令行中使用java –jar jenkins.war运行,也可以将jenkins.war放在tomcat中去执行。
3,  打开Jenkins的系统管理>系统设置:
a)         在jdk中填入jdk安装地址。
b)         在ant中填入ant安装地址。
c)         在最下面的邮件通知中设置邮箱的smtp地址等信息。设置完成后可以测试是否设置成功。
4,  打开系统管理>插件管理>可选插件,安装如下插件:
a)         ant
b)         Android Emulator Plugin
c)         Jenkins Emma plugin
d)         FindBugs Plug-in
5,  在Eclipse中新建一个Android项目以及测试项目,假设你的项目目录结构如下所示:
/workspace/android-app
/workspace/android-test
安装Apache Ant。
1.         在Eclipse workspace下为Android app项目添加ant,执行:
android update project -p android-app
2.         为测试项目添加ant,执行:
android update test-project -m ../android-app -p android-test
3.         现在app项目中生成了local.properties文件,这个文件应该在版本控制工具中设置为忽略;在test项目中现在生成了ant.properties和local.properties两个文件,这两个文件必须要加入版本控制工具中(SVN)。
4.         在命令行中执行下面的代码看看ant是不是成功运行了:
ant clean debug
5.         开启一个Android模拟器,然后在test工程下执行下面的代码看看测试工程是否可以成功运行:
ant all clean emma debug install test
6.         如果成功的话会在测试工程下生成coverage目录,内含一个名为coverage.html的文件,里面是测试用例的覆盖率等数据。

安装Emma
Emma用于在Jenkins中生成出Ant执行的测试用例的报表,上面我们测试后生成的是html格式的,但是要想在jenkins中生成图形等,则必须生成出xml格式的文件。
1,  打开SDK安装目录,打开tools/ant/build.xml,复制其中名为coverage的target到你的测试项目中的build.xml文件中。
2,  将<html outfile="coverage.html" />节点替换成:
<html outfile="coverage.html" />
<xml outfile="coverage/coverage.xml" />
3,  将<ehco>节点替换成:
<echo>Saving the report file in ${basedir}/coverage/coverage.xml</echo>
4,  再次运行:ant all clean emma debug install test命令后,在coverage文件夹中多了一个coverage.xml 文件的话则成功。

安装FindBugs
FindBugs用来找到你的项目中的bug,目前我还没有使用到它。不过Jenkins官方文档中的步骤将它配置了,所以我们也来做它的配置。
1,  下载FindBugs,将其中lib/findbugs-ant.jar 拷贝到Ant安装目录下的lib文件夹中。
2,  在app工程文件夹下的local.properties文件中加入:findbugs.home=** 其中**为你的findbugs的安装目录。
3,  如果你需要在R.java中查找bug的话则需要在app工程目录下添加一个名为findbugs-exclude.xml的文件,在其中写入下面的代码。
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<Class name="~.*\.R\$.*"/>
<Bug code="Nm"/>
</Match>
</FindBugsFilter>
4,  在app工程目录下的build文件中加入下面的代码。
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"/>
<target name="findbugs">
<mkdir dir="reports" />
<findbugs home="${findbugs.home}" output="xml" outputFile="reports/findbugs.xml" excludeFilter="findbugs-exclude.xml">
<auxClasspath path="${android.jar}" />
<class location="${out.dir}" />
</findbugs>
</target>
5,  执行ant clean compile findbugs 后在app工程目录下生成一个名为reports的文件夹,里面包含了一个名为findbugs.xml的文件。

配置jenkins
Jenkins环境修改:
1,  下载android-junit-report-1.2.6.jar(可以下载更新的版本),将它加入test工程的build path中。
2,  修改test project的AndroidManifest.xml,找到tag "instrumentation" 将属性"android:name" 的值改成 com.zutubi.android.junitreport.JUnitReportTestRunner。
3,  打开test工程下的build.xml,在</run-test-helper>节点后加入下面的代码:<echo>Downloading XML test report...</echo>
<exec executable="${adb}" fail>
<arg line="${adb.device.arg}"/>
<arg value="pull" />
<arg value="/data/data/${tested.manifest.package}/files/junit-report.xml" />
<arg value="junit-report.xml" />
</exec>
4,  找到其中名为test.runner的property节点,将它的值改为:com.zutubi.android.junitreport.JUnitReportTestRunner

配置App工程:
1,  添加一个自由风格任务,选择subversion,将app项目的svn地址填入(第一次使用的时候会要求提供svn账户密码)。
2,  添加一个Invoke Ant构建步骤,在其中的Targets填入clean compile findbugs。
3,  在高级选项中的properties填入下面内容(注意填自己的安装信息):sdk.dir=D:\\WORK\\ENVIROMENT\\ANDROID\\AndroidSDK
findbugs.home=D:\\WORK\\ENVIROMENT\\FingBugs\\ findbugs-2.0.0
4,  构建后选项选择:Publish FindBugs analysis results,然后填入:reports/findbugs.xml。
5,  选择Archive the artifacts,这样可以在每次构建后提供构建出来的apk版本。
6,  勾选E-mail Notification选项,在下面的recipients中填入需要接收构建异常信息的联系人邮件地址。勾选“每次不稳定的构建都发送邮件通知”选项。
配置test工程:
1,  添加自由风格任务,选择subversion,将test项目的svn地址填入。
2,  在Invoke Ant的target中填入:all clean emma debug install test。
3,  在build file中填入build.xml。
4,  在properties中填入sdk.dir=D:\\WORK\\ENVIROMENT\\ANDROID\\AndroidSDK。
5,  勾选Publish JUnit test result report,填入:junit-report.xml。
6,  勾选Record Emma coverage report,填入:coverage/coverage.xml。
7,  勾选E-mail Notification,如app工程配置。
所有配置工作到此结束,现在可以去跑了。

本文标签 , , ,

除非注明,文章均为( meiw@z3a105.com )原创,转载请保留链接: http://blog.z3a105.com/?p=116

Windows下Android项目搭建Jenkins持续构建+自动化测试:等您坐沙发呢!

发表评论





       ==QQ:122320466==

 微信    QQ群

推广

  • 104726drf320ff09r7i62f.jpg
  • 103217vn3333zbk3snwz2u.jpg

0

Aujourd’hui, une partie avec le développement du e-commerce, achats en ligne est devenu une partie de la vie pour beaucoup de gens. La mariage a commencé achats en ligne. Si vous choisissez achats les mariages en ligne, il peut être beaucoup moins cher que le salon de la Robe de mariée pas chermariée local, réduisant le budget de mariage. vous pouvez avoir beaucoup de choix si acheter de mariage en ligne. vous pouvez ramasser une robe de mariée bon marché sur Internet.
Piercing fascinerande figur, och nu tittar vi på 2016 senast brudklänning, kan du vara den vackraste bruden det!2016 senaste Bra brudklänning, söt temperament Bra design, romantiska spetsar blomma kjol, som du lägger till en elegant och charmig temperament.Kvinnan tillbaka mjuka linjer, människor brudklänningofta få en känsla av oändlig frestelse. Fall 2016 mässan, lämnar uppgifter om ditt bröllop charmig.
Yesterday afternoon, the Chinese team was training in the Guangzhou Gymnasium, when the reporter asked Zhao Yunlei the feeling of wearing the new cheap jersey , cheap jerseys online shopshe readily took a shirt from the bag crumpled ball to reporters, and she said with a smile: ” This shirt is light. ”Zhao Yunlei said: “Our material is very light like with the clothes of the tennis King Nadal, Federer, after the sweat, sweat does not drip down to the ground, when we do move, it is easy pace slipping if the sweat drip on the floor.”Tennis players Zhang Yawen, told reporters: “You might think the clothes attached to the body, fearing we swing will be affected, in fact, we do not feel anything, because the clothes are very light, very soft, put on quite comfortable. And it’s particularly good clothes to dry, washing and will dry in 15 minutes. ”
China’s sports enthusiasts NFL sweatshirt with mad love and the pursuit of, and therefore, NFL jerseys have a good market in China and development. China is a populous country, is the consumer, the economic momentum is so good, the sales prospects sportswear is immeasurable. With hot sales sweatshirt, but also to promote the importance of sports fans, on health, on the other hand is a matter of concern for the World Cup, fans wearing NFL jerseys and also can express themselves more fully love and obsession Therefore, NFL jerseys Wholesale jerseys online shopwholesale has good prospects and development in China.
ANTA-ANTA Sports Products Limited, referred to as ANTA Sports, Anta, is China’s leading sporting goods companies, mainly engaged in the design, development, manufacture and marketing of ANTA brand sporting goods, including sports footwear, apparel and accessories. Anta sweatshirt design advantages, warm stretch knit fabric, using Slim version of model, more personal fit, bid farewell to bloated, so wearing more stylish.GUIRENNIAO-This logo is a spiritual totem, smooth graphics implication unstoppable force; flexible deliver an elegant arc Wholesale jerseys china shop movement, strength and speed of the United States, a symbol of passion and rationality publicity “Heart” and “meaning”, “concept” unity; pass the fearless and enterprising mind, showing beyond the realm of self, to unstoppable force to create the future.XTEP-Xtep (China) Co., Ltd. is a comprehensive development wholesale jerseys china shop, production and marketing of Xtep brand (XTEP) sports shoes, clothing, bags, caps, balls, socks mainly large sporting goods industry enterprises.
There are a lot of fans in identifying the authenticity of the above cheap jerseys have great distress, so here to i will show you some methods to definitely affordable inexpensive cheap jerseys : Firstly, we should look at if it is working fine. China has been called the world’s factory, a lot cheap jerseys factories in China have foundries, but our cheap jerseys are all from here! Secondly, should to see whether it is the , we all know that it is difficult to get out of print once a genuine cheap cheap jerseys free shipping jersey was print. and we have all kind of stocka on the whole website, in other words, we have all you want ! Finally, look at the price, our price is not necessarily the lowest in the whole website but it must be most fair on the whole website, we certainly you will not regret later when you buy it. Of course, except that cheap jerseys, we also have the other products, such as socks, leggings and some other related products, everyone can enjoy the best services of here!