Personal observations on application testing and designing
Just some thoughts I've gathered based on talks by Ian Copper, Robert Martin... Coupling and cohesion, testing behaviors, TDD... and certainly some controversial suggestions.
bar = new Bar(“bar”); Chung chung = ChungFactor.create(bar); // Now I can have foo Foo myFoo = new Foo(bar, chung) // Simulate actual value Date date = new Date(); Integer value = 42; // Past 3 dates are mandatory for foo.getCurrentValue() to work myFoo.addValue(new Date(), null); myFoo.addValue(new Date(), null); myFoo.addValue(date, value); // OK now I can test something that requires foo // but that is *not* about foo
bar = new Bar(“bar”); Chung chung = ChungFactor.create(bar); // Now I can have foo Foo myFoo = new Foo(bar, chung) // Simulate actual value Date date = new Date(); Integer value = 42; // Past 3 dates are mandatory for foo.getCurrentValue() to work myFoo.addValue(new Date(), null); myFoo.addValue(new Date(), null); myFoo.addValue(date, value); // OK now I can test something that requires foo // but that is *not* about foo I just don’t care. Irrelevant for my test.
on what you’re testing Arguably more maintainable Don’t overuse it or your test will become overspecified Some people might try to hurt me for saying that
You communicate through a well-defined protocol to achieve your respective goals - you pay money, he lets you walk out with the bag of Cheetos. Either one of you can be replaced without disrupting the system. Tight: You and your wife. http://stackoverflow.com/questions/39946/coupling-and-cohesion
from gas to milk to ATM banking. Products and services have little in common, and the convenience of having them all in one place may not be enough to offset the resulting increase in cost and decrease in quality. High: The cheese store. They sell cheese. Nothing else. Can't beat 'em when it comes to cheese though.
code that does not work 2. GREEN : Make it work, committing whatever sins necessary in the process 3. Refactor while GREEN, not RED. Remove code smells, duplication, introduce design patterns. Do not introduce public classes