spring单元测试

spring3.0.4单位测试,看代码说话吧

测试类:

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.web.HttpRequestHandler;
@ContextConfiguration
public class TestUserManager extends AbstractTransactionalJUnit4SpringContextTests {

 @Autowired
 UserManager userManager;
 HttpServletRequest request;
 
 
 @Before
 public void setUp() {
  request = new MockHttpServletRequest();
 }
 
 @Test
 public void testPageBean() {
  }
 }
   @After
 public void tearDown() {
  request = null;
 }
}

  

配置文件:TestUserManager-context.xml

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<!-- ① 引入清单1定义的Spring配置文件 -->

<!--<import resource="classpath:/applicationContext.xml"/>-->
<import resource="classpath:/applicationContext-dao.xml"/>
<import resource="classpath:/applicationContext-manager.xml"/>
<import resource="classpath:/applicationContext-resources.xml"/>
<import resource="classpath:/applicationContext-service.xml"/>
</beans>

 

相关推荐