A key advantage of good refactoring and the MVC design pattern is that it makes it easier to validate the performance of your program using unit tests. A unit test is a test of a single, specific function of your program. Because both refactoring and the use of an MVC design pattern tend to break your program into smaller pieces, it is easier for you to write specific unit tests targeting individual parts of your program. Unit testing is a particularly useful tool when combined with refactoring, because a complete suite of unit tests allows you to verify that you are not introducing any errors as you move your code around.
A continual challenge in unit testing is how to test UI code. Testing a model is relatively straightforward, as most of the model functionality will not depend on user input. Testing the functionality of the interface itself can be more difficult because the behavior of the interface depends on user behavior that can be hard to encapsulate. In this section we'll show you how to use unit testing in wxPython, particularly the use of manually generated events to trigger behavior during a unit test.
Was this article helpful?