Your intention is to keep your tests fast, reliable and repeatable good. Removing network addiction is a great way to help achieve these goals.
Instead of being locked in the method as it is now, remember that the tool you are trying to use is called test- DRIVEN . Tests are not just a wrapper to make sure your code works as it is written. Its a way to learn how to improve your code to make it more reliable, reliable, reusable, etc.
To eliminate network dependency, you might consider passing a URL (your parameter name is already imageURL) instead of a string. This way you can create a URL on the local file system instead of a network location.
I also notice that your method really works a lot. A name that describes what it really does can be loadImageFromURLAndScaleItAndSaveItToDisk :. Why not break it down into several smaller, more verifiable methods? Perhaps the one that downloads the image from a URL that scales the image and stores the image on the local file system. You can test each individual part, and then do another unit test that checks your original method, comparing its results with the results of calling smaller methods in order.
I think I would also say that a good test, reliable and repeatable tests is a good goal, but if you want to make the test "slower" or "not 1000% reliable", OK , a test that provides value for you is better than Do not write a test because you do not consider it a test good enough .
I know that most of them are common, but I hope this helps.
Jonathan Arbogast Oct 09 '13 at 1:54 on 2013-10-09 01:54
source share