I am new to Mockito. For the code:
public class A{
public A{
...
B.fff(); //the function I want to mock
...
}
}
public class B{
public boolean fff(){
...
... //connect DB
...
}
}
For the unit test,
public class ATest{
@Test
public void test(){
A mock_a = new A();
Assert.assertNotNull(mock_a);
}
}
Because of the function "B.fff()" need connect the DB,so I would like to mock the function "B.fff()" with return true or false for let the test can work completely without environment.
I tried some code like:
public class ATest{
@Test
public void test(){
PowerMockito.when(B.fff()).thenReturn(true);
Assert.assertNotNull(new A());
}
}
but it isn't working.
Is there any solution by using Mockito(or PowerMock)?
Thanks.