Skip to Content
Python GUI Programming with Tkinter
book

Python GUI Programming with Tkinter

by Alan D. Moore
May 2018
Beginner to intermediate content levelBeginner to intermediate
452 pages
11h 26m
English
Packt Publishing
Content preview from Python GUI Programming with Tkinter

Writing a test case

Let's create a test case for the MyCalc class in the test_mycalc.py as follows:

from mycalc import MyCalcimport unittestclass TestMyCalc(unittest.TestCase):    def test_add(self):        mc = MyCalc(1, 10)        assert mc.add() == 11if __name__ == '__main__':    unittest.main()

The names of both your test modules and your test methods should be prefixed with test_. Doing so allows the unittest runner to automatically find test modules and distinguish test methods from other methods in your test case classes.

As you probably guessed, the TestCase class represents a test case. To make our test case for MyCalc, we subclass TestCase and start adding the test_ methods to test various aspects of our class. Our test_add() method creates a MyCalc ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python GUI Programming with Tkinter - Second Edition

Python GUI Programming with Tkinter - Second Edition

Alan D. Moore

Publisher Resources

ISBN: 9781788835886Supplemental Content