[TIP] Seeking testing framework for code that cannot be tested by Python unittest
robertc at robertcollins.net
Mon Jun 27 16:57:05 PDT 2016
On 24 June 2016 at 04:26, Goldberg, Arthur P <arthur.p.goldberg at mssm.edu> wrote:
> Hi Rob
> Yes, I have that impression about unittest, but could not locate
> documentation which teaches me how to use it to test my code.
> The system I want to test is a discrete event simulator. Its primary
> components are a simulation engine and a set of simulation objects which
> represent the components of the system being modeled.
> The initialization of a simulation program creates the simulation objects,
> each of which registers with the engine. Initialization must also create at
> least one event. Events are stored in the engine. The simulation is started
> by executing the engine’s scheduler method.
> The scheduler repeatedly chooses the next event and calls the event handler
> in the simulation object that receives the event. The event handler can
> schedule future events for any simulation object, including itself. The
> simulation ends when it runs out of events to process, exceeds a termination
> time, or fails.
> My tests use some real simulation objects and some test simulation objects.
> They exchange events with each other. I want the test objects to verify
> assertions about the state of the events they receive from the real
> simulation objects.
> I can show you code if that would help.
I'd write some code to setup the simulation ready to go, and to clean
up afterwards, and call that code from my tests. If raising an
exception from within the simulator will propogate out, then you can
use regular assert statements as well as any other exceptions you
desire to signal failure. You can also introspect your test objects
after the simulation finished to see if they detected an error.
More information about the testing-in-python