BP15: Don't depend on external static methods and properties, inject the dependencies instead

Unit testing

Try to unit test the code that contain these classes wih static methods. 

System.Math? And about System.IO.Path, File and Directory?

Did it go well? It didn't. Because you can't mock static methods. And that's the problem.

Do you remember HttpContext.Current? Have you tried to mock it? It was challenging. All these static properties could easily be replaced by the instance of concrete classes injected to the objec that need them.

Comments

No Comments Yet.
Be the first to tell us what you think.

Download Better Coder application to your phone and get unlimited access to the collection of enterprise best practices.

Get it on Google Play