PyUnit-Eclipse guide

PyUnit is a framework designed for repetitive testing of programs. Support for PyUnit can be found in most major APIs such as Eclipse etc.

Case : Hello

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.

[Image 1]

We can now add a PyUnit-test into our project as any other Python module

[Image 2]

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.

[Image 3]

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.

[Image 4]

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.

[Image 5]

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