spring 集成junit做测试

1.下载spring-test和junit 4

	<dependencies>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>3.1.3.RELEASE</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11-beta-1</version>
			<type>jar</type>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>3.1.3.RELEASE</version>
			<type>jar</type>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.javassist</groupId>
			<artifactId>javassist</artifactId>
			<version>3.16.1-GA</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
	</dependencies>


2.编写测试代码

package com.test.vid.service.webservice;

import static org.junit.Assert.*;

import javax.annotation.Resource;


import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.test.vid.model.UserLoginInfo;
import com.test.vid.utils.AppCommon;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})

public class UserLoginWebServiceCXFImplTest extends AbstractJUnit4SpringContextTests {
	@Resource
	private UserLoginWebServiceCXFImpl userLoginWebServiceCXFImpl;

	@Test
	public void testLogin() {
		UserLoginInfo userLoginInfo = new UserLoginInfo();
		userLoginInfo.setUserName("ychen");
		userLoginInfo.setPassword("111111");
		assertEquals(AppCommon.RET_CODE_SUCCESS,
				userLoginWebServiceCXFImpl.login(userLoginInfo).getRetCode());
	}

}


你可能感兴趣的:(spring 集成junit做测试)