- Stubs vs. Mocks
- Stubs
- provide specific answers to methods calls
- ex: myStubbedService.getValues() just return a String needed by the code under test
- used by code under test to isolate it
- cannot fail test
- ex: myStubbedService.getValues() just returns the stubbed value
- often implement abstract methods
- provide specific answers to methods calls
- Mocks
- "superset" of stubs; can assert that certain methods are called
- ex: verify that myMockedService.getValues() is called only once
- used to test behaviour of code under test
- can fail test
- ex: verify that myMockedService.getValues() was called once; verification fails, because myMockedService.getValues() was not called by my tested code
- often mocks interfaces
- "superset" of stubs; can assert that certain methods are called
- Stubs
↧
Answer by Relu Mesaros for What's the difference between a mock & stub?
↧