PyUnit is a framework designed for repetitive testing of programs. Support for PyUnit can be found in most major APIs such as Eclipse etc.
The Hello World example on the previous page is well suited for showing some of the PyUnit functionality in Eclipse which is relevant for this course. In the initial state the program has just been written in (Created a project, added a class, wrote the code) There are however no tests yet.
We can now add a PyUnit-test into our project as any other Python module
Choose as a template either "Unittest" or "Unittest with setUp and tearDown" (this time, take the one with the setUp and tearDown), write a name for your test module (at this course: test). Finally press Next.
WHen we have our test written in (copy it from the previous page), you can execute it by choosing (Run as -> Python unit-test) from the drop-down menu while the class is selected.
PyUnit will execute the tests and show the test set, where the number of failed tests are shown by the blue cross and the number of programming errors by the red cross. The spce below shows the error and failure notes.
If you want a more detailed view into what went wrong, you can select the test you want by clicking the corresponding row in the list.
When all the tests have passed the status bar of PyUnit will turn green. Try this yourself by testing the original code first and then after fixing the bug by adding the exclamation point.
Back to PyUnit-guide