I am new to programming and have implemented an onlinestore in python with a number of different features.
One of the submission requirements is to show evidence of testing, I have read about unit unittest in python and I am just wondering how you structure the tests when functions do not have a definitive answer, for example I have a function that returns all products in a mysql database as show below;
class TestSum(unittest.TestCase):
def test_get_all_products(input):
connection = get_sql_connection()
cursor = connection.cursor()
if input:
query = ("SELECT * FROM `online-store`.product WHERE name like
'%"+input+"%';")
else:
query = ("SELECT * FROM `online-store`.product;")
cursor.execute(query)
response = cursor.fetchall()
for row in response:
print ("Id=",row[0],"\t","Name=",row[1] , "\t","Price =£",row[2],"\t","
Supplier",row[4])
return response
I am wondering how I would test this function, what should the syntax be