Singletons are Pathological Liars
by Miško Hevery So you join a new project, which has an extensive mature code base. Your new lead asks you to implement a new feature, and, as a good developer, you start by writing a test. But since you are new to the project, you do a lot of explora…
Writing Testable Code
by Miško HeverySo you decided to finally give this testing thing a try. But somehow you just can’t figure out how to write a unit-test for your class. Well there are no tricks to writing tests, there are only tricks to writing testable code. If I gave…
by Miško HeverySo you discovered dependency injection and GUICE and you are happily refactoring and writing new tests for you code until you come across this circular reference.class A {final B b;A(B b){ this.b = b;}}class B {final A a;B(){ this.a =…
by Miško Hevery, Jonathan Wolter, Russ Ruffer, Brad Cross, and lots of other test infected GooglersThis guide lists principles that will help you write impossible to tests code. Or, avoiding these techniques will help you write code that can be tested…
by Miško HeveryEvery time I see Law of Demeter violation I imagine a haystack where the code is desperately trying to locate the needle.class Mechanic {Engine engine;Mechanic(Context context) { this.engine = context.getEngine();}}The Mechanic does no…