samedi 6 avril 2019

How to test code reliant on other events and GUIs?

I am creating a GUI using Tkinter and made the mistake of not creating tests before writing the code. I'm new to both GUI creation and testing and I'm rather confused on how to move forward.

Is there a not so difficult way to test a GUI other than manual testing?

How do I test methods that are reliant on other methods / user interaction?

I thought Unit Tests would be the way forward, but looking at tutorials they show tests on a method such as:

sum(x, y)

Which makes sense as the x and y can be assigned and an assertion made. But what if I don't have parameters here to easily assign?

One method I have is for letting the user load a CSV file from the directory:

    def csv_open(self):
        csv_file = tk.filedialog.askopenfilename()
        if not csv_file:
            return  # user cancelled

        if os.path.splitext(csv_file)[1] != ".csv":
            self.notify("You Must Select a CSV File", True)
            return

        self.csv_label.config(text=os.path.basename(csv_file))
        self.notify("CSV File Loaded")

How would I write a Unit Test for this, or is there another form of testing I should use?

Have I just written "untestable" code?

Aucun commentaire:

Enregistrer un commentaire