`

spirng 单元测试(一)

 
阅读更多
要把DateAccessServiceTest-context.xml放到classpath目录下

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:util="http://www.springframework.org/schema/util"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
         ">
  
  <import resource="spring-config.xml"/>
  <import resource="webapp-config.xml"/>
</beans>


import java.util.List;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import com.taskManager.DataAcessModel.Global;
import com.taskManager.service.IDateAccessService;



@ContextConfiguration
public class DateAccessServiceTest extends AbstractTransactionalJUnit4SpringContextTests
{
	
	@Autowired
	IDateAccessService iDateAccessService;
	
         // 每一个test方法都会执行
	@Before  
	public void setUp() {   
	   
		System.out.println(" Junit start::::::::;");

	} 
	
	
	@Test  
	public void testGetDate() {   
		 
		 List<Global> date = iDateAccessService.getDate();
		 Assert.assertNotNull(date);
		
	}
	@Test  
	public void testGetDate2() {   
		 
		System.out.println("ttt");
		
	}
         // 每一个test方法都会执行
	@After  
	public void tearDown() {   
	  
		System.out.println(" Junit end::::::::;");
	}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics