Recap

We can now summarize the essentials of the Testix approach:

  1. use Fake objects to simulate various entities

  2. use a Scenario object to define an exact set of demands or expectations

  3. the Scenario object not only defines our expectations, it is also used in a with statement to enforce them.

  4. return values from Fake objects may be specified using >>.

By requiring the developer to define his or her demands using a the Scenario concept, Testix lends itself in particular to Test Driven Development - think about testing first, write the code only after you have exactly defined what you want it to do.

We can also now recognize some major advantages over the mock objects from the Python Standard Library.

  1. Testix lends itself naturally to the Test Driven approach to development (TDD) through its Scenario concept and the “no less - no more” approach that makes it harder to change the functionality of code without changing the test first.

  2. test syntax is more visually similar to the code under test, e.g. the s.sock.send(b'the data') is visually similar to the same as the actual code socket.send(data). This makes tests more readable and easy to understand.

  3. Whatever expectations you define for you mock objects - they will be exactly enforced - defining expectations and enforcing them is one and the same.