junit 4 spring 自动化测试

 1 添加jar ,依赖jar 包围 spring-test,jar与 junit4.jar

 2 编写测试类

  

package com.test;

import java.util.List;

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 org.springframework.util.Assert;

import com.cee.resources.domain.BzrdSelect;
import com.cee.resources.service.BzrdSelectManager;

@ContextConfiguration(locations = { "applicationContext.xml",
		"applicationContext_sys.xml", "read-servlet.xml", "sfgl-servlet.xml",
		"usmp-servlet.xml" })
public class BzrdSelectManagerTest extends
		AbstractTransactionalJUnit4SpringContextTests {
	@Autowired
	private BzrdSelectManager bzrdselectmanager;

	@Test
	public void testFindAllTest() {
		List<BzrdSelect> testList = bzrdselectmanager.getAll();
		Assert.notNull(testList);

	}
}

   3 注意,classpath ,加载配置文件要放在测试类同级的目录中。

   4  标注的含义 @Autowired 自动装配  @Test测试方法

  5 Assert 方法的逻辑 notNull 不为空
 

你可能感兴趣的:(spring,xml,servlet,JUnit)