主要是工作中作接口测试用例 debug 时,有上下文依赖的用例在调试时,需要同时跑两条及以上的用例,
如果能在每次调单条用例的时候,把前面已经跑过的,而后面又对跑过的用例有依赖的,缓存住,就好了,
这时候就想到了 redis,可以把前面 debug 的用例的结果放到 redis,后面 debug 别的用例时,就取出来用。
{
"afterSql": [
],
"apiUrl": "http://app.jollytest.com/user/emailExists.do",
"beforeSql": [
],
"description": "1.0 Email是否存在",
"method": "POST",
"name": "APP2--/user/emailExists.do--20180109-1643",
"requestContentType": "json",
"requestParameters": {
"email": "%%{<linuxTime>8}@jollytest.com"
},
"responseAsserts": [
{
"assertCondition": "is",
"jsonPath": "$.messageType",
"value": 0
},
{
"assertCondition": "is",
"jsonPath": "$.messageCode",
"value": "0"
}
],
"responseCode": 200,
"responseContentType": "json",
"updateRequestParameters": [
]
},
{
"afterSql": [
],
"apiUrl": "http://app.jollytest.com/user/register.do",
"beforeSql": [
],
"description": "1.1 用户注册",
"method": "POST",
"name": "APP2--/user/register.do--20180202-1100",
"requestContentType": "json",
"requestParameters": {
"userName": "17539911@jollytest.com",
"password": "kkkkkk"
},
"responseAsserts": [
{
"assertCondition": "is",
"jsonPath": "$.messageType",
"value": 0
},
{
"assertCondition": "is",
"jsonPath": "$.messageCode",
"value": "0"
}
],
"responseCode": 200,
"responseContentType": "json",
"updateRequestParameters": [
{
"localJsonPath": "$.userName",
"referenceBodyType": "request",
"referenceCaseName": "APP2--/user/emailExists.do--20180109-1643",
"remoteJsonPath": "$.email"
}
]
}
我安装在 centos 7 的机器上,具体步骤略
$ cd src
$ ./redis-server ../redis.conf
在 pom 文件中增加 redis 连接的 jar 包,就像连 mysql 可以使用 mysql-connector-java 的包一样,使用的版本是:2.9.0
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>
public class RedisUtils {
private static final Jedis jedis = new Jedis("127.0.0.1", 6379);
private RedisUtils() {
}
public static Jedis getRedis() {
return jedis;
}
public static void main(String[] args) {
Jedis jedis = getRedis();
log.debug(jedis.ping());
jedis.set("a", "b");
jedis.set("a", "c");
System.out.println("" + jedis.del("a"));
}
}
@Test
public void pushMsg() {
RedisUtils.getRedis().publish("topic:clg.biz", "Hellow World2");
}
@Test
public void getMsg() {
RedisUtils.getRedis().subscribe(new JedisPubSub() {
@Override
public void onMessage(String channel, String message) {
System.out.println(message);
super.onMessage(channel, message);
}
}, "topic:clg.biz");
}
发布订阅模式,了解一下,暂时还没有实际用到
比如有用例名:xxProject_xxFeature_xxTestObject,就是用例名可能比较长,用这个字符串的 hashcode 作 key 来存进去应该能减少空间
大家在工作中是如何使用 redis 的?