I'm trying to write a TestNg test case. It is to check that what happens when the customer puts an exception, I am using a powermaker to mimic the client call. Below is my test method (only unitathet has been cut and the code has not been tested
@Test (Expected Exception = {ExecutionException.class}) Public Zero Hanks ExceptionTest () Exception { // Set customer expectations LLCClient llcClientMock = PowerMock.createMock (LLCClient.class); Lifttraction Action Processor Test Class = New LiftTrack Action Action Processor (LLCClitMock); llcClientMock.liftRestriction (EasyMock.anyObject (BigInteger.class), EasyMock.anyObject (BigInteger.class) , EasyMock.anyOb Ject (String.class), EasyMock.anyBoolean ()); EasyMock.expectLastCall () andThrow (New RuntimeException ()); PowerMock.replayAll (); PowerMock.verifyAll () ;; // Exam method testClass.process (exchangeMock ) Run}
Although the fake throws the right exception, TestNG fails the test case with the output given below:
org.testng.TestException : ** Expected exception com Example.common.ExecutionException but found organization .testng.TestException **: Expected exception com.example.common.ExecutionException but com.example.common.ExecutionException found: org.testng.internal.Invoker.handleInvocationResults (Invoker.java:1498) at java.lang.RuntimeException org.testng.internal.Invo org.testng.TestRunner on ker.invokeTestMethods org.testng.internal.TestMethodWorker.invokeTestMethods (TestMethodWorker.java:128) on org.testng.internal.TestMethodWorker.run (TestMethodWorker.java:111) (Invoker.java:1245) .privateRun org.testng.TestRunner.run (TestRunner.java:617) to (TestRunner.java:767) .runSequentially (SuiteRunner on org.testng.SuiteRunner.runTest (SuiteRunner.java:334) on org.testng.SuiteRunner. Java: 329) org.testng.SuiteRunner.privateRun (SuiteRunner.javaociety91) org.testng.SuiteRunner.run (SuiteRunner.java), on org.testng.SuiteRunnerWorker.runSuite (on SuiteRunnerWorker. Java: 52) org.testng.SuiteRunnerWorker.run (SuiteRunnerWorker.java:86) on org.testng.TestNG.run on SuitesSequentially (TestNG.java:1203) org.testng.TestNG.runSuitesLocally (TestNG.java:1212) org .testng.TestNG.run (TestNG.java:1036) at org.testng.remote.RemoteTestNG.run at (RemoteTestNG Java: org.testng.TestException: 111) org.testng.remote.RemoteTestNG.initAndRun (RemoteTestNG.java : 204) org.testng.remote.RemoteTestNG.main (RemoteTestNG.java:175) Expect the exception due to on org.testng.internal.Invoker.handleInvocationResults (Invoker.java:1498) org.testng.internal.Invoker On .invokeMethod (at least java.lang.RuntimeException: com.example.common.ExecutionException but com.example.common.ExecutionException found com: org.testng.internal.Invoker.invokeTestMethod on Invoker.java:754) (org.testng Invoker.java:901) at .internal.Invoker.invokeTestMethods (Invoker.java:1231) ) ... 16 due to more. Example.common.ExecutionException: java.lang.RuntimeException on com.example.fees.actions.AbstractFeesProcessor.process (AbstractFeesProcessor.java:54) Xample.fees.actions.AbstractFeesProcessorTest.handleExceptionTestAuditing (AbstractFeesProcessorTest.java:109) on com.e At sun.reflect.NativeMethodAccessorImpl.invoke0 (original method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl. Cited in java.lang.reflect.Method.invoke (Method.java:601) on org.testng.internal.MethodInvocationHelper.invokeMethod (MethodInvocationHelper.java:80) on org.testng.internal.Invoker (DelegatingMethodAccessorImpl.java:43) org.easymock.internal.MockInvocationHandler.invoke (MockInvocationHandler.java:46) on org.easymock.internal.ObjectMethodsFilter.invoke (at java.lang.RuntimeException: .invokeMethod (Invoker.java:714) ... 18 more because ObjectMethodsFilter.java:85) $ Proxy12.liftRestriction (unknown source com.example.fees.actions.LiftRestrictionActionProcessor.execute on com.example.fees.actions.AbstractF) (LiftRestrictionActionProcessor.java:46) on Eesprocessor.process ( AbstractFeesProcessor.java:44) ... 25 more
The test condition works properly if below The commands are determined:
@Test (Expected Exceptions = {Execution Exception.Clash})
But I do not want to do this Because it beats the purpose of the test.
No comments:
Post a Comment