Mocks Flashcards Preview

Software Unit Tests > Mocks > Flashcards

Flashcards in Mocks Deck (17)
Loading flashcards...
1

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;

2

How does the mock work behind the scenes (Moq)?

Usually by using generics and lambda. Strong typed.

3

What's a unit?

It's a situational thing. An unit can be composed by one or more classes that make sense together.

4

What are all the terminologies used for mocks?

Fakes, dummies, stubs and mocks.

5

What's a fake?

A non-suitable-for-production working implementation.

6

What's a Dummy?

Simply satisfy parameters, never used.

7

What's a stub?

Provide answers to calls (method returns meaningful data).

8

What's a mock?

Verify interactions.

9

How to mock methods and return values with Moq?

mock.Setup(lambda to select the method).Returns(True)

10

How to automatically created nested objects of the mocked object?

It's automatic, but can also be defined with : {DefaultValue = DefaultValue.Mock}

11

How to mock all properties and therefore enable tracking on them all as well?

SetupAllProperties. Remember to call it first.

12

What's state-based testing?

Check the state/value of props/methods.

13

What's behavior-based testing?

Check how the classes interacts/behaves between themselves (cache hit/miss) via method/prop monitoring.

14

What's a strict and loose mock?

Strict mock requires you to specify all the mocks manually. Loose mock auto create class and props.

15

how to embrace code with a statement

ctrl + k + s

16

What's a partial mock?

partial mocks is usually mocks over classes or specific function like date now.

17

How to mock protected methods?

Use the protected namespace and then create a interface that matches the mocked class, then use the As method.