I find myself repeating the same code when writing unit tests, for example... When writing functions that work with files, In the setup for the test i often write some code to create a file (in a directory specified with an environment variable) populate it then after i have run the test I destroy the file and folder.
To me this seems the correct way of doing things as the test is completely independent of anything other than an environment variable which can easily be set on multiple os's.
However I am clearly violating DRY principle by writing this file creating code every time, so I thought I could make a helper package that simplifies this, however i feel that would mean the test would become "dependant" on the helper package.
So the questions are.
In this situation should the DRY principle be violated so as to avoid unnecessary dependence's?
It's ok to create a helper package as long as it can be imported from an external location like git hub?
- Is there another approach (perhaps using dependency injection)?