GoConqr has a new look! Let us know what you think.

Flashcards

python test doubles mocks fakes

Andrew Sperazza python English 14 cards

Cards in this deck (14)

  1. 1what is a test double>?a stand in for an actual class
  2. 2what are the different types of test doubles?-dummy object
    -stubs
    -spys
    -mocks
    -fakes
  3. 3what is a test stub?any object that has no logic or behavior, ex) just returns values
    and
    it has same interface than class mocked
  4. 4how do you start using stubs?from unittest.mock import Mock
    variable = Mock(ClassToMock)
  5. 5how do you represent a file in memory?import io
    x=io.StringIO(self.text)
  6. 6what is a fake?a test double that uses both logic and functionality, which of course we are using for testing purposes
  7. 7what are some common uses for fakes?replace
    file
    db
    webserver
  8. 8what is a mock?mocks are like stubs, but they make assertions what happens in test cases. ie they can cause the test to fail.
  9. 9what are the 3 types of assertions?check return value or exception
    check a state change (use public api)
    check a method call (use mock or spy)
  10. 10what can a mock do with function calls?test if the method was called with a particular object
    and
    particular arguments
  11. 11how do you test if a function was called using a mock?set a boolean if a function is called, and assert that boolean value is true
  12. 12what is a spy?same as a mock, but watches and records test status, it can let test run, a mock will fail straight away. you can check spy status later
  13. 13how do you use monkeypatching to change classes at runtime?with patch('module.Classname') as test_class:
    test_instance=Mock()
    test_instance.myvar=1
    or use decorator @patch('module.Classname')
  14. 14when would you use monkeypatching over refactoring class to make it use mocks?when you cannot change class signatures

Information

Description
python (python unit testing) Flashcards on python test doubles mocks fakes, created by Andrew Sperazza on 18/01/2017.
Created by
Andrew Sperazza
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?