Version 1 (modified by wouter, 2 months ago) ( diff )

--

UnitPy

UnitPy is a toolbox with python annotations similar to the java unit test annotations, using @Test @Before @After @RunWith etc. UnitPy also provides a tool to discover and run tests.

UnitPy does not need the test class to extend unittest.TestCase, and the test class constructor does not need modifications (TestCase requires the name of the test function to be passed as additional argument). This enables to use the test class also as normal class.

The @RunWith annotation is to be placed right before the class definition. @RunWith allows the class to be run in different "styles", depending on the argument provided to @RunWith.

annotation
@RunWith(JUnit4ClassRunner)normal test
@RunWith(Parameterized)parametric test

JUnit4ClassRunner

This runs all methods annotated with @Test inside the class. If there is a method annotated @Before, this is called first. Then the test method is called (with no arguments) Finally, if there is a method annotated @After, that method is called

Parameterized

The class must contain a static method annotated with @Parameters. This annotation indicates that the method takes no parameters and that it returns list of lists. Every inner list is to be used to call the constructor, so the number of arguments must match the init function parameters.

For every method M inside the class that is annotated with @Test, the following now happens:

  • create an instance of the test class, with the next inner list arguments

If there is a method annotated @Before, this is called.

  • execute the test method M
  • if there is a method annotated @After, that method is called
Note: See TracWiki for help on using the wiki.