I need to write tests for a code-base and I had some confusion regarding how to go about this. I search the internet + stack overflow however I couldn't find a suitable answer to my question.
Suppose you have code that does something very specific. For example, the function needs to be provided with a root_directory (e.g. Database) which is required to check if the String provided already exists in the database. The code would break if the correct root_directory isn't provided, and if the String isn't in the correct format it would break as well. For the sake of context, look at the simple code below. We provide the code with the root_dir and the string to search for.
root_dir = /Documents/MyDatabase/
specific_string_to_find = "A01_55678"
def get_all_db_files(root_dir, specific_string_to_find):
searchFor(specific_string_to_find, root_dir)
This is all quite straightforward. However, if I have to write a test for such a function, would I provide my test with the correct root_dir where the database exists? Would I provide it with the correct format of the String? If I don't provide the correct information, the code will break. And if I do provide it, I feel like it renders the test void since I already know exactly what's going in. Any guidance would be much appreciated. I apologize if the question is inappropriate, however, I require some guidance for this specific use case.
Aucun commentaire:
Enregistrer un commentaire