Skip to content

Test doubles

alessandrofg edited this page Sep 22, 2013 · 2 revisions

Currently, to test the OWTF framework some test doubles have been used in order to isolate the features tested. These test doubles are based mainly in flexmock, a python test library that provides features to build fake objects, mocks and stubs. More information about this library could be found at the documentation site. A part of this library, there are some already implemented test doubles in the tests.testing_framework.doubles package, such as:

  • files.FileMock: This class simulates a text file object. You can use this test double when you want to control the content of a file that your program has to read, and also to avoid all the IO operations with the disc, improving the speed of your tests.
  • mock.StreamMock: This is a simple test double used to replace a stream object. It records all the input provided to the stream, and you can retrieve this information through the get_content method.
  • mock.OrderedExecutionMock: This is a more complex object. It makes sure that some methods are called in the same order as expected. Firstly, you have to pass to the constructor the target object. After that, record the correct execution order with the *register(method_name, args) method. After the execution, you have to verify if every expected call has been satisfied with the verify_order method. The OrderedExecutionMock raises an exception in four cases:
    • ExecutionOrderError: if the execution order is wrong.
    • MissingExecutionError: verify_order has been executed, but there are expectations not satisfied.
    • MissingRegisteredCalls: there are some method calls not registered.
    • BadArgumentException: the current arguments passed to the method do not match with the arguments expected.
Clone this wiki locally