如何在RestAPI项目中集成Mockito Test

时间:2016-02-12 04:50:57

标签: java spring-mvc mockito

我在mockito中使用了Stockbing the entity后的Mockito方法。但是在调用服务iam时获取服务的null对象

并且在SpringDAO.xml中包含了Package。我在测试时使用Bean注入,我收到如下错误:

org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
            java.lang.reflect.InvocationTargetException
                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:497)
                at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
                at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
                at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
                at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
                at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
            Caused by: org.testng.TestNGException: 
            Cannot instantiate class org.example.test.api.controller.NewYoutubeTest
                at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:38)
                at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:387)
                at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:299)
                at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:115)
                at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:200)
                at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:120)
                at org.testng.TestRunner.initMethods(TestRunner.java:409)
                at org.testng.TestRunner.init(TestRunner.java:235)
                at org.testng.TestRunner.init(TestRunner.java:205)
                at org.testng.TestRunner.<init>(TestRunner.java:153)
                at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:536)
                at org.testng.SuiteRunner.init(SuiteRunner.java:159)
                at org.testng.SuiteRunner.<init>(SuiteRunner.java:113)
                at org.testng.TestNG.createSuiteRunner(TestNG.java:1299)
                at org.testng.TestNG.createSuiteRunners(TestNG.java:1286)
                at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
                at org.testng.TestNG.run(TestNG.java:1057)
                at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:77)
                at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:159)
                at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:99)
                at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:106)
                ... 9 more
            Caused by: java.lang.reflect.InvocationTargetException
                at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
                at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
                at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
                at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
                ... 29 more
            Caused by: java.lang.NullPointerException
                at org.example.test.api.controller.NewYoutubeTest.<init>(NewYoutubeTest.java:140)
                ... 34 more

0 个答案:

没有答案