MockTesting Flashcards
How can we test software economically? What are the 5 principles of testing?
- Specify Input and Output
- Seperate Creation and Testing -> a software developer shouldn’t test his own program
- Completeness of Tests -> Test cases also must consider invalid and unexpected input
- Testing is an Investement -> avoid throwaway test cases. Use automatic testing, that can be repeated at any point in time
- Error Clusters -> errors tend to com ein clusters, means: if you find an error in a section, this section is very likely to have more errors.
What is regression testing?
When we save test cases and run them again later after changes to other components of the program.
What’s a Test Double?
Any object or component that is installed in place of the real component in order to run a test.
Which of the three types of test doubles
- Fakes
- Stubs
- Spies
is. ..
a) the least complex
b) the most complex
a) Stubs
b) Fakes
What can a Mock test do, that a simple unit test can’t?
Behavior of the System under test can be tracked by the use of mock object
e.g. can we check how many times a method was called
What’s the pattern for mock testing?
- Create a mock object
- Specify the expected behavior of the mock
- Test / use the mock
- Verify behavior
Name some reasons, when we would use mock objects
The actual object has non-deterministic behavior
The actual object is difficult to set up
The actual object is slow
The actual object has a user interface
The test needs to ask the real object about how it was used (→ e.g., if a callback function was called)
The actual object does not yet exist
What’s the purpose of verify(….) ?
To test the behavior with the mock object // e.g. to check if a method got called
What is “Stubbing”?
When we teach the mock object how to behave when…thenReturn… or doReturn…when….