We have all read it or heard someone talk about masalah master forex. Static Methods are Death to Testability”. As you can see, it returns the human readable version of the machine name.
Now there is an issue with this. So the requirements for our use of the above utility class is to create a URL to an image hosted on the local machine. Now you can stop laughing at the example. The purpose of this tutorial is not to find some painful testing feature, it’s to show where the ability to mock static method calls is useful. To record our expectations we do exactly as we normally would.
Instead of listing out all of the mock objects we want to replay, this method handles it for us. The above code is all you need to test those “nasty” static methods. I never said it would be pretty. But what it does do is it implements the test correctly and demonstrates my point. Just because you can’t do something with your current toolset doesn’t mean that it’s bad. It just means you may need to re-evaluate your toolset. As always, I’m excited to read your comments!
What about other ways of addressing the same issue? This is why I don’t like powermock. It screws with the class loader and using pertest is NOT a good option. Do I still use static methods?