1. pom.xml
junit junit 4.12 test org.springframework spring-test 4.2.5.RELEASE
2. 定义一个测试基类:
import org.junit.runner.RunWith;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;@RunWith(SpringJUnit4ClassRunner.class)//表示整合JUnit4进行测试@ContextConfiguration(locations={"classpath:applicationContext.xml"})//加载spring配置文件public class BaseJunit4Test {}
3. 测试类
package com.zerotest.lotus;import org.junit.Test;import org.springframework.beans.factory.annotation.Autowired;import com.sltas.application.entrance.model.EntranceParameter;import com.sltas.entrance.dao.EntranceParameterMapper;public class SpringRedisTest extends BaseJunit4Test { @Autowired private EntranceParameterMapper entranceParameterMapper; @Test public void test01() { EntranceParameter epm01 = new EntranceParameter(); epm01.setCategory("aaaaaa"); epm01.setMerchId(111261); epm01.setParamKey("aaa - key"); epm01.setParamValue("aaa = value"); entranceParameterMapper.insert(epm01); /* EntranceParameter epm = entranceParameterMapper.selectByPrimaryKey(5); System.out.println(epm.getParamKey()); System.out.println(epm.getCategory()); System.out.println(epm.getParamValue()); */ }}