NutzCN Logo
问答 请问nutzboot如何写单元测试呢
发布于 2431天前 作者 muyiluop 2334 次浏览 复制 上一个帖子 下一个帖子
标签:

我是按照下面这样写的,但是会报错。

public class TestBase extends Assert {

    protected Ioc ioc;

    @Before
    public void before() throws Exception {
        ioc = new NutIoc(new ComboIocLoader("*anno", "cn.wizzer","org.nutz","io.nutz"));
        _before();
    }

    @After
    public void after() throws Exception {
        _after();
        if (ioc != null) {
            ioc.depose();
        }
    }

    protected void _before() throws Exception {}
    protected void _after() throws Exception {}
}
 @Test
    public void testLogin(){
        LoginService service = ioc.get(LoginServiceImpl.class);
        NutMap resp = service.login("", "");
        System.out.println(Json.toJson(resp));
    }

@IocBean
@Service(interfaceClass=LoginService.class)
public class LoginServiceImpl implements LoginService{
    @Inject
    private PropertiesProxy conf;
    @Inject
    RedisService redisService;
.....
}

org.nutz.ioc.IocException: IocBean[loginServiceImpl] throw Exception when creating

	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:240)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:270)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:160)
	at cn.wizzer.app.api.test.TestLoginService.testLogin(TestLoginService.java:16)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.RuntimeException: IocBean[loginServiceImpl] fail at field=[conf]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	... 28 more
Caused by: org.nutz.ioc.IocException: IocBean[class:org.nutz.ioc.impl.PropertiesProxy] none ioc bean match class=org.nutz.ioc.impl.PropertiesProxy
	at org.nutz.ioc.impl.NutIoc.getByType(NutIoc.java:460)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:66)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 30 more
添加回复
请先登陆
回到顶部