Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating File Just for the Sake on Unit Test

Tags:

unit-testing

This might be an interesting question. I need to test that if I can successfully upload and fetch the PDF file. This works for the text based files but I just wanted to check for PDF. For this unit test to run I need a PDF file. There are couple of options. I can create a dummy PDF file and store it some folder and read that file and save the file to the system. But now, my unit test is dependent on the PDF file. So, anyone who runs the unit test must have the PDF file which is kinda bad.

Another way for me is to create a PDF file. This is not a big deal as I can simply create a dummy file with the .pdf extension OR I can even use some PDF third party tool to create PDF file.

Another way also is to embed the PDF document as an embedded resource and then extract that from the assembly.

What do you think is the best way to handle this issue?

like image 751
azamsharp Avatar asked Dec 30 '22 09:12

azamsharp


1 Answers

Save a PDF file with your tests in a resources directory. Your tests should be as simple as possible, and creating a file is just one more point that could fail.

like image 50
Bill the Lizard Avatar answered Jan 08 '23 11:01

Bill the Lizard