读书人

Test种@Before方法

发布时间: 2013-08-04 18:26:16 作者: rapoo

Test类@Before方法
cache的定义要在before外面,以供所有的test公用

/** *  */package com.taobao.cmp.jury.tair.cache;import java.util.Map;import org.junit.After;import org.junit.Before;import org.junit.Test;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.taobao.cmp.jury.tair.JuryTairClientGroup;/** * @author qianyi.zby *  */@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations={"classpath:/spring-test.xml"})public class UserTaskOverTimeCacheTest {UserTaskOverTimeCache cache;/** * @throws java.lang.Exception */@Beforepublic void setUp() throws Exception {      ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(                  "spring.xml");           cache = (UserTaskOverTimeCache)           context.getBean("userTaskOverTimeCache"); }/** * @throws java.lang.Exception */@Afterpublic void tearDown() throws Exception {System.out.println("@After");}@Testpublic void testRead() {//final UserTaskOverTimeCache cache = new UserTaskOverTimeCache(556,//tairGroup);Map<Long, Long> map = cache.get(2053128170l);System.out.println(map);}@Testpublic void testWrite() {//final UserTaskOverTimeCache cache = new UserTaskOverTimeCache(556,//tairGroup);int map = cache.add(2053128170l, 123l, 3);System.out.println(map);}@Testpublic void testClear() {//final UserTaskOverTimeCache cache = new UserTaskOverTimeCache(556,//tairGroup);boolean map = cache.delete(2053128170l);System.out.println(map);}}


公共部分写在Before标签里面

读书人网 >互联网

热点推荐