[Tutor] How to write tests for main() function that does not return anything

Ben Finney ben+python at benfinney.id.au
Wed Feb 3 16:20:48 EST 2016


Steven D'Aprano <steve at pearwood.info> writes:

> I think the right answer is that testing main() is *not* a unit test,
> it's an integration test. You're testing that the application as a
> whole works the way you expect, rather than testing individual units
> of the application (functions, class, methods, modules).

Alternatively, if you can define what ‘main’ should do in isolation from
the rest of the program, then you *can* test it in unit tests.

That requires designing ‘main’ such that you can explicitly describe its
interactions with the rest of the program; inputs, outputs, side
effects, expected behaviour when any of them change.

That exercise may lead you to conclude “wow, this actually does quite a
lot and it's difficult to describe” — and then it's a short step to
realising you should re-design the function so it has a more narrow
specification :-)

-- 
 \            “The idea that He would take his attention away from the |
  `\       universe in order to give me a bicycle with three speeds is |
_o__)  just so unlikely that I can't go along with it.” —Quentin Crisp |
Ben Finney



More information about the Tutor mailing list