How do I run unittest on a Tkinter app?

后端 未结 3 2105
眼角桃花
眼角桃花 2020-12-05 00:44

I\'ve just begun learning about TDD, and I\'m developing a program using a Tkinter GUI. The only problem is that once the .mainloop() method is called, the test

3条回答
  •  伪装坚强ぢ
    2020-12-05 01:20

    One thing you can do is spawn the mainloop in a separate thread and use your main thread to run the actual tests; watch the mainloop thread as it were. Make sure you check the state of the Tk window before doing your asserts.

    Multithreading any code is hard. You may want to break your Tk program down into testable pieces instead of unit testing the entire thing at once (which really isn't unit testing).

    I would finally suggest testing at least at the control level if not lower for your program, it will help you tremendously.

提交回复
热议问题