1. pom.xml
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
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());
*/
}
}
来源:oschina
链接:https://my.oschina.net/u/2669637/blog/1973406