by Miško Hevery Recently many of you, after reading Guide to Testability, wrote to telling me there is nothing wrong with static methods. After all what can be easier to test than Math.abs()! And Math.abs() is static method! If abs() was on instance method, one would have to instantiate the object first, and that may prove [...]
Entries Tagged as 'Rant'
Static Methods are Death to Testability
December 15th, 2008 · 55 Comments
Tags: OO · Rant · Testability
My main() Method Is Better Than Yours
August 29th, 2008 · 7 Comments
By Miško Hevery People are good at turning concrete examples into generalization. The other way around, it does not work so well. So when I write about general concepts it is hard for people to know how to translate the general concept into concrete code. To remedy this I will try to show few examples [...]
Tags: Advice · Rant · Testability
Root Cause of Singletons
August 25th, 2008 · 38 Comments
Since I have gotten lots of love/hate mail on the Singletons are Pathological Liars and Where Have All the Singletons Gone I feel obliged to to do some root cause analysis. Lets get the definition right. There is Singleton the design pattern (Notice the capital “S” as in name of something) and there is a [...]
Tags: Advice · Rant · Testability
Where Have All the Singletons Gone?
August 21st, 2008 · 24 Comments
by Miško Hevery In Singletons are Pathological Liars we discussed the problems of having singletons in your code. Let’s build on that and answer the question “If I don’t have singletons how do I ensure there is only one instance of X and how do I get X to all of the places it is [...]
Tags: Advice · OO · Rant · Testability
Changing Developer Behavior – Part 1
August 19th, 2008 · 2 Comments
by Miško Hevery | 19 August 2008 | republished from alphaITjournal So you’ve figured out a better way of doing things, but how do you get everyone to change the way they work and start writing code in this better way? This is something I face daily in my line of work as a best [...]
Tags: Advice · Rant · Testability Explorer
Singletons are Pathological Liars
August 17th, 2008 · 77 Comments
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 exploratory “What happens if I [...]
Tags: Advice · OO · Rant · Testability
Top 10 things which make your code hard to test
July 30th, 2008 · 29 Comments
by Miško Hevery So 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 you testable code you would have no [...]
Tags: Advice · Rant · Testability
How to Write 3v1L, Untestable Code
July 24th, 2008 · 15 Comments
by Miško Hevery, Jonathan Wolter, Russ Ruffer, Brad Cross, and lots of other test infected Googlers This 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. Make Your Own Dependencies – Instantiate objects using new in the middle of [...]
Tags: Advice · Rant · Testability
Dynamic Languages are not Inherently More Testable
July 13th, 2008 · 6 Comments
Lately a lot of people have been arguing that dynamic languages (JavaScript, Python, Ruby) are inherently more testable then static languages such as Java. (See Java is Naturally Untestable, Comments) But in my opinion it is a bad idea and a misdirected argument. Mutable global state is bad Replacing methods at runtime is mutating global [...]
Tags: Dynamic Languages · Rant