背景:
以下步骤是根据开发给我搭建好的自动化项目,复刻出来,至于为什么这样做,,我还在慢慢研究
场景:
项目接口自动化,能够在gocd上自动运行
一、项目搭建
1、创建项目gradle
2、删掉mian(可删可不删,只是基本没用)
3、修改为intelliJ IDEA
4、build.gradle文件添加所需要的依赖,并加载
dependencies {
//jackson
implementation 'com.fasterxml.jackson.core:jackson-core:2.9.8'
// implementation 'com.fasterxml.jackson.core:jackson-core:2.11.2'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.8'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
// implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.16.0'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.9.8'
//hutool
implementation group: 'cn.hutool', name: 'hutool-all', version: '5.8.15'
//lang3
implementation 'org.apache.commons:commons-lang3:3.12.0'
//obs
implementation 'com.huaweicloud:esdk-obs-java-bundle:3.22.3'
//lombok
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
//jdbc
testImplementation 'org.springframework.boot:spring-boot-starter-jdbc'
//test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.rest-assured:rest-assured:4.5.1'
testImplementation 'io.rest-assured:json-path:4.5.1'
testImplementation 'io.rest-assured:xml-path:4.5.1'
testImplementation 'com.alibaba:fastjson:1.1.54.android'
//DBRider
testImplementation 'com.github.database-rider:rider-core:1.32.3'
testImplementation 'com.github.database-rider:rider-junit5:1.32.3'
testImplementation 'com.github.database-rider:rider-spring:1.32.3'
//excel
testImplementation 'com.alibaba:easyexcel:3.0.5'
//mockito
testImplementation 'org.mockito:mockito-inline:4.9.0'
}
5、在test-java下创建项目包com.***,并在该目录下添加springBootApplication启动文件
二、配置环境
需要配置的:url,切换环境
1、切换环境:添加环境配置文件,dev表示当前使用application-dev的配置文件,有多个环境,写多个环境的application-**即可
application-dev中配置环境url,数据库等环境相关内容
2、配置URL,RestAssured.baseURI默认是本机
表示取带有“env”的值,此处能取dev环境中的yml中的dev的url
取url,并在接口调用中拼接
3、获取token
登录接口获取token,后续可以直接用asDev()
使用举例: