Further Testing Flashcards
What are invariants
Assertions about classes/objects that should not change
Invariants should always be true
Give advantages of test-driven development
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
What are test suites used for
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 do you implement mock objects
Implement an interface for production code
Implement the interface in a mock object for unit testing
Give 3 uses of mock objects
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
What is a mock object
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