Mocks Flashcards

1
Q

Why creating mocks?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

Usually by using generics and lambda. Strong typed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What’s a unit?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are all the terminologies used for mocks?

A

Fakes, dummies, stubs and mocks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s a fake?

A

A non-suitable-for-production working implementation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What’s a Dummy?

A

Simply satisfy parameters, never used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What’s a stub?

A

Provide answers to calls (method returns meaningful data).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What’s a mock?

A

Verify interactions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to mock methods and return values with Moq?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to automatically created nested objects of the mocked object?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

SetupAllProperties. Remember to call it first.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What’s state-based testing?

A

Check the state/value of props/methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What’s behavior-based testing?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What’s a strict and loose mock?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

how to embrace code with a statement

A

ctrl + k + s

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What’s a partial mock?

A

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

17
Q

How to mock protected methods?

A

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