【发布时间】:2016-05-16 17:13:00
【问题描述】:
我已经编写了 Junit 测试类来测试特定的方法。此方法中处理的变量之一是弹簧注入,通过从属性文件中获取值。
下面是我的测试方法
@Test
public void myTestMethod() {
//invoking the method to be tested
Assert.assertTrue(updateGroceries());
}
这是要测试的类,
public class ToBeTested {
//Spring injected value
String categories;
public boolean updateGroceries() {
List<String> categoryList = StringUtils.convertStringToList(categories);
}
在上面的类中,类别变量是弹簧注入的。 这是属性文件内容:
categories = Dals,Pulses,Dry Fruits,Edible Oil
现在在运行我的 Junit 方法时,执行失败,因为依赖注入失败。因为我要测试的代码在 tomcat 上运行。我想在不运行 tomcat 的情况下测试代码。请提出一些解决方案。
【问题讨论】:
标签: java spring tomcat junit dependency-injection