News for hackers. Stuff that matters.
Re:How to write untestable code by yread on Friday November 06, 2009 @03:47AM (#925704)
What's wrong with

Create Utility Classes and Functions/Methods - For instance, you have a String which is a URL you're passing around (obeying "Use Primitives Wherever Possible"). Create another class with static methods such as isValidUrl(String url)

if the function is a deterministic function (I guess it could be implemented as a simple test against regex) why is is difficult to test? I get that its better to use the system one or your own URL class, but thats really about OO and not testing!

Re:How to write untestable code by roam on Friday November 06, 2009 @06:46AM (#925844)
The keyword is "static". You'll often want to use a mock implementation rather than connecting to a remote server, checking for a 404 error and returning true or false - every time you run your tests.

Loosely coupled objects will allow you to do that, but how would you redefine the behavior of something static?