mercredi 23 mai 2018

Testing tkinter application

I wrote a small application using python 3 and tkinter. Testing every widget, even though there are not many of them feels daunting so I wanted to write a couple of automated tests to simplify the process. I read some other question that seemed relevant to this problem but none fit my needs. Right now I'm doing the testing in a very simple manner - I invoke the command for every widget and manually click through it to see if it works. It does make things a bit faster, but I constantly run into some problems - i.e. I can't automatically close popup windows (like showinfo) even with using libraries to simulate keyboard clicks (namely pynput). Is there an efficient approach for testing applications using tkinter?

Here is the code I use right now:

import tkinter as tkinter
import unittest
from mygui import MyGUI

class TKinterTestCase(unittest.TestCase):
    def setUp(self):
        self.root = tkinter.Tk()


    def tearDown(self):
        if self.root:
            self.root.destroy()

    def test_enter(self):
        v = MyGUI(self.root)
        v.info_button.invoke()
        v.close_button.invoke()
        v.btnOut.invoke()


if __name__ == "__main__":
    unittest.main()

Aucun commentaire:

Enregistrer un commentaire