分享

spring 集成junit做测试

 且看且珍惜 2014-12-01

1.下载spring-test和junit 4

  1. <dependencies>  
  2.     <dependency>  
  3.         <groupId>org.springframework</groupId>  
  4.         <artifactId>spring-context</artifactId>  
  5.         <version>3.1.3.RELEASE</version>  
  6.         <type>jar</type>  
  7.         <scope>compile</scope>  
  8.     </dependency>  
  9.     <dependency>  
  10.         <groupId>junit</groupId>  
  11.         <artifactId>junit</artifactId>  
  12.         <version>4.11-beta-1</version>  
  13.         <type>jar</type>  
  14.         <scope>test</scope>  
  15.     </dependency>  
  16.     <dependency>  
  17.         <groupId>org.springframework</groupId>  
  18.         <artifactId>spring-test</artifactId>  
  19.         <version>3.1.3.RELEASE</version>  
  20.         <type>jar</type>  
  21.         <scope>test</scope>  
  22.     </dependency>  
  23.     <dependency>  
  24.         <groupId>org.javassist</groupId>  
  25.         <artifactId>javassist</artifactId>  
  26.         <version>3.16.1-GA</version>  
  27.         <type>jar</type>  
  28.         <scope>compile</scope>  
  29.     </dependency>  
  30. </dependencies>  


2.编写测试代码

  1. package com.test.vid.service.webservice;  
  2.   
  3. import static org.junit.Assert.*;  
  4.   
  5. import javax.annotation.Resource;  
  6.   
  7.   
  8. import org.junit.Test;  
  9. import org.junit.runner.RunWith;  
  10. import org.springframework.test.context.ContextConfiguration;  
  11. import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;  
  12. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;  
  13.   
  14. import com.test.vid.model.UserLoginInfo;  
  15. import com.test.vid.utils.AppCommon;  
  16.   
  17.   
  18. @RunWith(SpringJUnit4ClassRunner.class)  
  19. @ContextConfiguration(locations={"classpath:applicationContext.xml"})  
  20.   
  21. public class UserLoginWebServiceCXFImplTest extends AbstractJUnit4SpringContextTests {  
  22.     @Resource  
  23.     private UserLoginWebServiceCXFImpl userLoginWebServiceCXFImpl;  
  24.   
  25.     @Test  
  26.     public void testLogin() {  
  27.         UserLoginInfo userLoginInfo = new UserLoginInfo();  
  28.         userLoginInfo.setUserName("ychen");  
  29.         userLoginInfo.setPassword("111111");  
  30.         assertEquals(AppCommon.RET_CODE_SUCCESS,  
  31.                 userLoginWebServiceCXFImpl.login(userLoginInfo).getRetCode());  
  32.     }  
  33.   
  34. }  


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多