Further Testing Flashcards

1
Q

What are invariants

A

Assertions about classes/objects that should not change

Invariants should always be true

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

Give advantages of test-driven development

A

Helps you design your code better
You see code from the user’s perspective not the developer’s

If your class is very difficult to test, then you should modify your design

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

What are test suites used for

A

To test multiple classes to run as a single batch

Also, allow us to run a specific subset of unit tests from multiple test classes

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

How do you implement mock objects

A

Implement an interface for production code

Implement the interface in a mock object for unit testing

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

Give 3 uses of mock objects

A

When the real object:

has non-deterministic behaviour
is difficult to set up
has behaviour that is hard to trigger
is slow
has a user interface
doesn't exist yet
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a mock object

A

Sometimes we need to test an object but it’ll rely on other objects, mock objects are placeholder objects that allow testing of this method

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