框架:jenkins+testng+maven+java+github
1.jenkins环境搭建
安装jenkins->安装插件->新建项目->配置github代码库->拉取代码->构建触发器(什么时候执行)->配件构建方式(构建后做什么)->安装插件(若是构建Android
应用,安装Gradle plugin
之后,或者执行命令行)->构建后处理(APK上传至蒲公英,或者发送测试报告)
分支写*/master即可
备注:
- 要在jenkins中配置jdk和maven的环境
- 构建触发器:“Poll SCM”,它的意思是,定时检查版本库,发现有新的提交就触发构建
- 在“Build”中,默认的Root POM是
pom.xml
。如果pom.xml
不在根目录下,就填入子目录,例如:wxapi/pom.xml
。 - 在Goals and options中,填入需要执行的mvn命令
2.github的用法
注册账号->github网站上创建仓库->仓库同步至本地->项目文件放入此仓库中->上传
仓库同步至本地:$ git remote add origin git@github.com:michaelliao/learngit.git
上传:git add .-> git commit -m "备注" ->git push origin master
其它命令:git status 查看状态 git diff 查看文件作了什么修改
备注:使用前首付要用git bash创建秘钥,然后把此秘钥粘贴至github官网,这样本地和远程仓库就建立了连接,然后是用gitbash登录
$ git config --global user.name "Your Name" $ git config --global user.email "email@example.com"
详细使用指导请看:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
3.maven的使用
pom.xml —-用于标识该项目是一个Maven项目
maven仓库:把jar包统一管理起来,所有的Maven项目只需要按照配置的依赖关系,从仓库中引用即可
-DgroupId 项目包名com.springmvc
-DartifactId 项目名称springMVCStudy
maven命令: mvn clean install(去pom.xml目录下运行此命令)
编译:mvn clean compile(编译好的class文件放在target文件夹下)
测试:mvn clean test(测试程序成功后会在target下生成一个test-classes目录)
打包:mvn clean package(会在target目录下生成springMVCStudy-1.0-SNAPSHOT.jar文件)
安装:mvn clean install(把生产的jar文件上传到Maven本地仓库)
运行:java -cp targetspringMVCStudy-1.0-SNAPSHOT.jar com.springmvc.App
pom.xml文件内容
添加可运行testng
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <suiteXmlFiles> <suiteXmlFile>testng.xml</suiteXmlFile> </suiteXmlFiles> </configuration> <version>2.20</version>
添加可指定要运行的测试类
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.9</version> <configuration> <includes> <include>**/*.java</include> </includes> <!--includes标签是指定了任何路径下,任何java类都执行测 试 --> <excludes> <exclude>**/*ServiceTest.java</exclude> </excludes> <!--excludes标签是指定了任何路径下,以ServiceTest结尾的不执行测试。若一个测试类既在<includes>中,也在<excludes>时,则按这个测试类最终在哪一边来执行, --> </configuration> </plugin>
添加jenkins才可找到配置文件
<build> <resources> <resource> <directory>src/config</directory> </resource> </resources> </build>