您的位置:首页 > 编程语言 > Java开发

Spring与Dao-Jdbc模板-使用Spring的JUnit4测试

2017-04-12 15:43 369 查看
Spring与Dao-Jdbc模板-使用Spring的JUnit4测试

环境搭建参考:http://blog.csdn.net/leisure_life/article/details/70143114

注意:使用Spring的JUnit4测试需要在搭建好的环境中再添加两个jar,
spring-aop-4.2.1.RELEASE.jar
spring-test-4.2.1.RELEASE.jar


package com.hk.springdao.test;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.hk.springdao.beans.Student;
import com.hk.springdao.service.IStudentService;

/**
*
* @author 浪丶荡
*
*/
@RunWith(SpringJUnit4ClassRunner.class)//运行环境
@ContextConfiguration(locations="classpath:applicationContext.xml")

public class MyTest_spring {
@Autowired
private IStudentService studentService;
@Test
public void testAdd(){
Student stu = new Student("浪丶荡",18);
studentService.addStudent(stu );
}
@Test
public void testRemove(){
studentService.removeStudent(2);
}
@Test
public void testModify(){
Student stu = new Student();
stu.setId(3);
stu.setAge(10);
stu.setName("黑旋风");
studentService.modifyStudent(stu);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring