junit4 单元测试service(Spring)方法

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.job36.admanage.service.AdAdTypeService;
import com.job36.admanage.vo.AdAdTypeVO;


public class AdTypeTest {
	ApplicationContext dsContext = null;
	AdAdTypeService adAdTypeService = null;
	AdAdTypeVO adAdTypeVO = null;

	@Before
	public void init() throws Exception {
		dsContext = new ClassPathXmlApplicationContext(new String[] {
				"applicationContext.xml", "applicationContext-dao.xml",
				"applicationContext-service.xml" });
		adAdTypeVO = new AdAdTypeVO();
		adAdTypeVO.setTypeId(1);
		adAdTypeVO.setTypeName("banner");
		adAdTypeVO.setMessage("测试");
		adAdTypeService = (AdAdTypeService) dsContext.getBean("AdAdTypeService");
	}

	@Test
	public void findByCondition() {
		assertEquals(adAdTypeService.findByCondition(adAdTypeVO).getListAdAdTypeVO().get(0), adAdTypeVO);
	}
}

你可能感兴趣的:(DAO,spring,xml,单元测试,JUnit)