Spring JUnit 编写及测试

最近经常使用Spring,但是项目放在web上运行,每次启动web容器很是费事,就写了个测试Spring的用例,模板如下,需要的jar包,自己可以到jar114上下载,速度都很快。

添加JUnit4的包以及junit-dep.jar、spring-test3.0.jar包

测试类的模板如下:


import javax.annotation.Resource;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.founder.immune.service.IWsEhrInoculationBO;


@RunWith(SpringJUnit4ClassRunner.class)

//添加spring的上下文配置文件
@ContextConfiguration(locations={"classpath:/spring/*.xml"})

//@Transactional //是否开启事务完全由自己决定
public class TestWsEhrInoculationBO
{

//注入对应的资源

@Resource
private IWsEhrInoculationBO wsEhrInoculationBO;

@BeforeClass
public static void setUpBeforeClass()
  throws Exception
{
}

@Test
public void testSave()
{
  wsEhrInoculationBO.saveEhrInoculations("");

}

}

猜你喜欢

转载自xiyuhanfei.iteye.com/blog/1607402