Mocks Flashcards
Why creating mocks?
External dependency costs money to be called (e.g main frame or cloud calls);
To be able to test non-deterministic dependencies (TimeNow);
Support parallel development (real dependency not yet developed);
Improve test predictability/reliability;
How does the mock work behind the scenes (Moq)?
Usually by using generics and lambda. Strong typed.
What’s a unit?
It’s a situational thing. An unit can be composed by one or more classes that make sense together.
What are all the terminologies used for mocks?
Fakes, dummies, stubs and mocks.
What’s a fake?
A non-suitable-for-production working implementation.
What’s a Dummy?
Simply satisfy parameters, never used.
What’s a stub?
Provide answers to calls (method returns meaningful data).
What’s a mock?
Verify interactions.
How to mock methods and return values with Moq?
mock.Setup(lambda to select the method).Returns(True)
How to automatically created nested objects of the mocked object?
It’s automatic, but can also be defined with : {DefaultValue = DefaultValue.Mock}
How to mock all properties and therefore enable tracking on them all as well?
SetupAllProperties. Remember to call it first.
What’s state-based testing?
Check the state/value of props/methods.
What’s behavior-based testing?
Check how the classes interacts/behaves between themselves (cache hit/miss) via method/prop monitoring.
What’s a strict and loose mock?
Strict mock requires you to specify all the mocks manually. Loose mock auto create class and props.
how to embrace code with a statement
ctrl + k + s