So I’m creating unit tests for all of my scripts, many of which arent oo, and have main-loop code. I was wondering what the standard is for the location of creating unittest classes in relation to the affected script. Should the unit test be in a separate file which imports the script, and then function-alize the mainloop code? Or can it shoved at the end of the the related script?
Share
You should separate your tests into a file of their own, and extract functions from your main so that they can be tested.
(After you’ve extracted the functions, you might notice that a lot of data is being shared between them, hinting that you should be creating a class.)
You’ll have a file like this:
And a file separate test file that tests those
func_*functions.Also, like @eli-bendersky says, those
func_*functions should be extracted into their own module if they are all related enough, so they can easily be reused by other scripts, but this is a start.