【问题标题】:JUnit Test cases failing while running using Maven but works with EclipseJUnit 测试用例在使用 Maven 运行时失败,但可以与 Eclipse 一起使用
【发布时间】:2013-04-04 14:58:20
【问题描述】:

我有一个 Junit 测试用例,如果我使用 Maven 运行,它就不起作用。但是当我使用 Eclipse 运行时,同样的测试用例可以工作。 我的Junit类是这样的。

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations = {"classpath:/test-config.xml"} )
public class TestDaoImpl { 
private final static Logger logger = Logger.getLogger(TestDaoImpl.class);

@Autowired
private MyDaoImpl myDao;

@Test
public void testMyDao() throws Exception {
logger.info("Called testMyDao()================");
     // here myDao is null and throwing NullPointerException in sunfire log.
     // But this works when I run using Eclipse.
List<MyObj> objList = myDao.getList();

}

@Test
public void testMyCode() throws Exception {
logger.info("Called testMyCode()================");
     // this test case works with Maven
List<MyObj> objList = MyClass.getList();

}



}

【问题讨论】:

  • test-config.xml 在哪里?
  • 在路径 src/test/resources
  • 这个问题对你有帮助吗? stackoverflow.com/questions/3571149/…
  • 不,这对我没有帮助。我知道这种情况,这是 Maven 的预期行为。就我而言,它不会注入 DAO。其他测试用例正在使用 Maven。
  • 有人帮我解决这个问题吗??

标签: spring maven junit


【解决方案1】:

sunfire 插件丢失。添加后它开始工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-16
    • 2011-07-24
    • 2012-08-05
    • 2015-03-11
    • 2016-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多