unit testing - Why it doesn't throw any exceptions when attempting to mock a singleton using either Mockito or PowerMock? -
i have singleton class "fake"
public class fake{ private static false instance; private fake(){ } public static false getinstance(){ if(instance == null) instance = new fake(); homecoming instance; } public string getteststring(string s){ homecoming s; } }
i want create mock false object can mock method calls non-static method getteststring(string s). have used both mockito , powermock (mockito extension) in way comes below.
//using mockito false fake = mockito.mock(fake.class); //using powermock false fake = mock(fake.class);
in both cases, code attempting mock singleton (with private constructor) expect exception occur, works. suspect there wrong , maybe not working actually.
mocking doesn't instantiate class, creates proxy it. having private constructor or constructor parameters doesn't create difference.
the behavior you're seeing normal , expected.
unit-testing testing singleton mockito powermock
No comments:
Post a Comment