import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import redis.clients.jedis.Jedis;
public class redisTest {
/**
public static void main(String[] args){
//连接redis服务器,
Jedis jedis = new Jedis("127.0.0.1", 6379);
//权限认证
jedis.auth("lp1234");
}
* */
//使用testNG测试
private Jedis jedisClents; //申明放在外面后函数的调用,提供客户端关闭与打开
@BeforeTest
public void setup(){
jedisClents=new Jedis("127.0.0.1", 6379);//连接redis服务器,
jedisClents.auth("lp1234");////权限认证,链接密码
System.out.println("1");
System.console();
}
@AfterTest
public void Aftertest(){
jedisClents.close();//测试之后关闭
}
@Test
public void testString(){
jedisClents.set("1","编号001");//设定想要的String参数
System.out.println(jedisClents.get("1"));//查询输出想要的结果
jedisClents.set("name","xiaoming");
System.out.println(jedisClents.get("name"));
jedisClents.set("age","100岁");
System.out.println(jedisClents.get("age"));
jedisClents.set("home","余杭区");
System.out.println(jedisClents.get("home"));
jedisClents.append("name", " is my lover");//字段拼接
System.out.println(jedisClents.get("name"));
}
@Test
public void testDel(){
jedisClents.del("home");//删除一个key
if (jedisClents.get("home")==null){
System.out.println("home的值为空");
}else{
System.out.println(jedisClents.get("home"));
}
}
}
使用testNg测:
testngRedis.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestAll" parallel="classes" thread-count="3">
<test name="case01">
<!--<parameter name="x" value="1999" />-->
<!--<parameter name="y" value="10" />-->
<!--<parameter name="mun" value="3" />-->
<!--<groups>-->
<!--<run>-->
<!--<exclude name="test1" />-->
<!--<include name="test2" />-->
<!--</run>-->
<!--</groups>-->
<classes>
<class name="redisTest.redisTest"></class>
</classes>
</test>
</suite>
网友评论