【发布时间】: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。
-
有人帮我解决这个问题吗??