I’m just starting to get into test development and I’m struggling to understand what to test. There are a lot of foobar examples out there, but I’m having difficulty knowing how to test my project units. For example, take this function which simple returns the lines of a text file as a list:
def getLines(filename):
try:
f = open(filename,'rb')
lines = f.readlines()
f.close()
except:
break
return lines
If this was your function, what would you test for? You don’t need to write the code, just tell me in broad terms if you like.
Thanks
So your function would return an empty list if the filename is invalid and would returns a list with all your lines if filename is valid
You could define a KnownValues dictionary with a filenames and number of lines in the file, like so,
Then you could write an assertEqual to count the number of items in the list that the function is returning