Skip to main content

Posts

Showing posts with the label Coding TDD Refactoring Agile

How to test a static dependency used inside a class...

This is a question that keeps coming up and I know if you're practicing it's a no brainer but I keep getting asked this by devs (I'm no testing God!). The long answer is to read this book and pay attention when talking about ' inserting a seam '. The short answer is carry on reading... Now several people (read Jimmy Bogard ) have already answered this but here is my take on this looking at my current client, they have a lots of deeply nested static dependencies - these are implicit dependencies and what you really want to is explicit dependencies because they are easily testable. So I see a lot of classes like this nested deeply in some object graphs. public class Foo { private string _ url ; private string _ connectionString ; private string _user; public Foo() { _ url = System.Configuration.ConfigurationManager.AppSettings[" SomeUrl "]; _ connectionString = System.Configuration.Config...