0

I am trying to Mock the object but failing.

Class A {
protected SomeResponse someRespsoonse;


public SomeResponse mapping(){

someResponse = new SomeResponse();

return someResponse ;
} 
}

Then i need to test it with following class:

@RunWith(MockitoJUnitRunner.class)
@PrepareForTest(A.class)
class ATest{
@Mock
A a = Mocktio.mock(A.class);
@Mock               
SomeResponse someResponse = Mockito.mock(SomeResponse.class);                              

@Test
testMyResponse{                
someResponse.setErrorInfo("500");                

PowerMockito.whenNew(SomeResponse.class).withNoArguments().thenReturn(someResponse);                
a.mapping();                

// some blah blah              

}}                          

Issue is am not able to populate the SomeResponse object from the test class. I went through the Stackoverflow and google. but couldn't get thing which am looking for.

Deepak Negi
  • 119
  • 3
  • 13

1 Answers1

0

You are using whenNew() of PowerMockito, so change your RunWith Runner from Mockito to PowerMock.

@RunWith(PowerMockRunner.class)
@PrepareForTest(A.class)
class ATest{
kswaughs
  • 2,967
  • 1
  • 17
  • 21
  • now am not able to do Test Coverage though test cases are running. – Deepak Negi Aug 27 '15 at 11:54
  • Running junit test cases with PowerMockRunner or MockitoJunitRunner are like running with normal junit test suite or runner, They have nothing to do with cobertura coverage. check the how & what cobertura plugin and configurations you are using. – kswaughs Aug 27 '15 at 12:01
  • eclEmma is coverage tool default which comes with eclipse – Deepak Negi Aug 27 '15 at 12:47
  • I usually run the cobertura report with maven plugins. So no idea on eclEmma tool. Better post another question with subject on eclEmma coverage tool in eclipse, also inform that u used powermockito framework, some one will provide you the solution. – kswaughs Aug 27 '15 at 13:07
  • it looks like you wont get cobertura coverage with powermock. see the references [http://stackoverflow.com/questions/23363212/powermock-eclemma-coverage-issue](http://stackoverflow.com/questions/23363212/powermock-eclemma-coverage-issue). – kswaughs Aug 27 '15 at 13:11