Entries from July 2008

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

Breaking the Law of Demeter is Like Looking for a Needle in the Haystack

July 18th, 2008 · 20 Comments

by Miško Hevery Every 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 not care for the Context. You can tell because Mechanic does not store the [...]

Tags: Testability

Top 10 Things I do on Every Project

July 16th, 2008 · 23 Comments

Here is a list of things I do on every project these days and I highly recommend that you do the same. The result is that: (1) It is very easy for new developers to come up to speed on a project like this to quickly; (2) The installation process for the users of the [...]

Tags: Advice

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

How to Think About the “new” Operator with Respect to Unit Testing

July 8th, 2008 · 44 Comments

By Miško Hevery Unit Testing as the name implies asks you to test a Class (Unit) in isolation. If your code mixes Object Construction with Logic you will never be able to achieve isolation. In order to unit-test you need to separate object graph construction from the application logic into two different classes The end [...]

Tags: Testability

Testing UI – part 1

July 5th, 2008 · 14 Comments

Lately I have been getting a lot of questions on how to test User Interface(UI) code. People always claim that UI testing is very hard or even that it is not possible. I think that with the right kind of design, UI testing is just as easy as testing any other piece of code. Let [...]

Tags: Flex