| 1 | = UnitPy |
| 2 | |
| 3 | 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. |
| 4 | |
| 5 | 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. |
| 6 | |
| 7 | The @RunWith annotation is to be placed right before the class definition. |
| 8 | @RunWith allows the class to be run in different "styles", depending on the argument provided to @RunWith. |
| 9 | |
| 10 | ||= annotation =|| |
| 11 | ||{{{@RunWith(JUnit4ClassRunner)}}}||normal test|| |
| 12 | ||{{{@RunWith(Parameterized)}}}||parametric test|| |
| 13 | |
| 14 | == JUnit4ClassRunner |
| 15 | This runs all methods annotated with @Test inside the class. |
| 16 | If there is a method annotated @Before, this is called first. |
| 17 | Then the test method is called (with no arguments) |
| 18 | Finally, if there is a method annotated @After, that method is called |
| 19 | |
| 20 | |
| 21 | == Parameterized |
| 22 | The class must contain a static method annotated with @Parameters. |
| 23 | This annotation indicates that the method takes no parameters |
| 24 | and that it returns list of lists. Every inner list |
| 25 | is to be used to call the constructor, so the number |
| 26 | of arguments must match the __init__ function parameters. |
| 27 | |
| 28 | For every method M inside the class that is annotated with @Test, the following now happens: |
| 29 | * create an instance of the test class, with the next inner list arguments |
| 30 | If there is a method annotated @Before, this is called. |
| 31 | * execute the test method M |
| 32 | * if there is a method annotated @After, that method is called |