我的好友张益达。
2017-03-27 09:12maven中用不了单元测试,普通的java项目中可以使用,控制台及junit无动作
package cn.itcast.core.test;
import java.util.Date;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import cn.itcast.core.dao.TbTestDao;
import cn.itcast.core.pojo.TbTest;
import cn.itcast.core.service.TbTestService;
//spring引入junit4测试环境
@RunWith(value=SpringJUnit4ClassRunner.class)
//加载spring配置文件进而加载spring运行环境
@ContextConfiguration(locations={"application-context.xml"})
public class TestTbTest {
@Autowired
// 注入
private TbTestDao tbDao;
@Autowired
private TbTestService tbService;
@Test
public void testTbTest(){
TbTest tb = new TbTest();
tb.setName("张三");
tb.setBirthday(new Date());
tbDao.insertTest(tb);
}
public void testTbTestService(){
TbTest tb = new TbTest();
tb.setName("李四");
tb.setBirthday(new Date());
tbService.insertTest(tb);
// throw new RuntimeException();
}
}
- 点赞
- 回答
- 收藏
- 复制链接分享
2条回答
为你推荐
- servlet调用service中的方法报错(项目是部署在maven中的)
- java
- intellij-idea
- java-ee
- maven
- tomcat
- 2个回答
- java项目进行maven install的时候 报java.lang.AssertionError 异常。急需大佬支援!!!
- java
- maven
- eclipse
- 2个回答
- Maven中的test测试类ClassNotFoundException
- java
- maven
- intellij-idea
- 2个回答
- 关于java/maven项目导包的疑问
- java
- spring
- maven
- jar
- eclipse
- 3个回答
- 如何在Linux(Ubuntu)服务器上部署maven项目?
- java
- maven
- intellij-idea
- ubuntu
- linux
- 1个回答