When using mockito, I guess i'm supposed to use when().thenreturn to customize the return value, even that's different from the real method. I just got confused that if everything is mocked (or fake?), how does mockito work to test if the method truly works well?
Asked
Active
Viewed 354 times
-2
-
1It doesn't. That's why you can't mock **everything**. It also means some people write tests that are completely useless, but they don't even understand why. Testing is an art form in its own right, so don't think you're a good tester even if you might be good at programming. – Kayaman Dec 10 '19 at 07:24
-
Not familiar with Java or mockito in particular, but normally you will not mock the method you're suppose to be testing. You mock calls to other classes/functions/APIs that are outside the scope of the piece of code that you want to test. The idea is to make sure that the code you want to test works or not, independent of outside code. – Azer Dec 10 '19 at 07:30
1 Answers
0
By using Mokito, you can mock the dependent calls and you can specify the return value so when the actual method call happened you will get specified value.
The main reason doing the mocking is that we do not want to perform the database call or network call or other backend work which may or may not be available during the test cases execution.

ankit patel
- 13
- 3
-
Is it like when I'm trying to test methods of List, like List
, but class Student has many dependencies, and just mock a Student instance can do this? – Sakary Dec 10 '19 at 09:01