测试方法中使用dao的时候提示,缺少propertiesProxy。于是写成了下面这样
public class MyNutTestRunner extends NutTestRunner {
public MyNutTestRunner(Class<?> klass) throws InitializationError {
super(klass);
}
//可以不写,最后是被super.createIoc调用
public Class<?> getMainModule() {
return MainLauncher.class;
}
/**
* 可覆盖createIoc,实现参数覆盖, bean替换,等定制.
*/
protected Ioc createIoc() {
Ioc ioc = null;
try {
ioc = new NutIoc(new ComboIocLoader("*js", "ioc/", "*anno", "cn.wizzer", "org.nutz", "io.nutz", "com.zhumaoyu.quantization"));
//=================以下为关键=========
//因为测试类里找不到propertiesProxy,这里手动注入
NbApp nbApp = new NbApp();
nbApp.prepareBasic();
nbApp.prepareConfigureLoader();
PropertiesProxy propertiesProxy = nbApp.getAppContext().getConf();
ioc.addBean("propertiesProxy", propertiesProxy);
//============
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return ioc;
}
}