mercredi 29 avril 2020

How do i write a Unit Test for my functions that takes no parameters (Python)

I have a program which using tkinter, allows a user to input his email, and receive updates on the following technology stack (Python, Chrome, Selenium). Nevertheless, i only have one class with a lot of functions, and im trying to write unit tests for each of them, but i don't know how to start as i have not found any help trying to research on it. I'll attach a function from my code and if anyone here can help me write a unit test for it, ill use it as a guide to write my other function. Thanks in advance.

def emailGet(self):
    """
    This function shows all email in the database in an array, to make it easier to send emails to all
    available emails in the database
    :return:
    """
    # Creates the connection from the database.py
    conn = sqlite3.connect("email.db")
    c = conn.cursor()

    c.execute("SELECT *, oid FROM email")
    self.records = c.fetchall()
    logging.info("This is all the emails in the database :" + str(self.records))
    print("This is all the emails in the database : " + str(self.records))
    self.get_records = ""

    for self.i in self.records:
        self.get_records += str(self.i[0] + ",")
        # print(get_records)
        self.new_record = self.get_records[:-1]
        logging.info("New record" + str(self.new_record))
        print(self.new_record)

    conn.commit()
    conn.close()

Aucun commentaire:

Enregistrer un commentaire