Tutorial: Unit Testing


Home » Support » Index of All Documentation » Introduction for New Users » Wing IDE Tutorial »

Wing's Testing tool makes it easy to run and debug units tests written for the unittest, doctest, and nose unit test frameworks.

Let's try this out now. First, open up Project Properties and under the Testing tab insert a Test File Pattern that is set to Glob / Wildcard and test_*.py. This tells Wing which of your project files are unit test files. Press OK or Apply and bring up the Testing tool from the Tools menu. This should now contain an entry for the file test_example1.py:

/images/doc/en/intro/testing.png

Next press Run Tests in the Testing tool. You should see two of the three tests pass, and one will fail. You can expand the tree to see details of the failed tests, including any output printed by the test and the exception that occurred. Double clicking on the test results and exception will take you to the relevant code.

/images/doc/en/intro/testing-results.png

Now run the failed testFailure in the debugger by right clicking on it and selecting Debug Test. Wing should stop at the exception and you can use the debugger on the test as you would for any other Python code.

Note that you can also run tests from the editor by clicking on the test you want to run and selecting Run Tests at Cursor from the Testing menu.

Environment

When unit tests are run in the Testing tool, by default they run in the same environment that is used for debugging and executing code. This can be changed by specifying a Launch Configuration to use instead, with Environment under the Testing tab of Project Properties or File Properties on the unit test file.

« 1.13. Tutorial: Other Editor FeaturesTable of Contents1.15. Tutorial: Version Control Systems »