Monday, August 15, 2011

Should You Unit Test Interaction with Static Methods?

No. You should not. Here's an example:

def a_good_method
Logger.log(self, "This is a call to a static log method")
# do some other thing here
end

If you are somehow mocking this static method, you are potentially making it dangerous for other places where this static method is used. Eventually, this will create red test results that are hard to find and make your tests dependent on each other.