JUnit is the brainchild of Kent Beck. He was initially a SmallTalk programmer, who wrote a really simple test framework for SmallTalk. This was back in the 90s, when Java was getting big, so he decided learning it was the way forward. His SmallTalk test framework was already making waves in the SmallTalk community and his friend Erich Gamma (a Java developer) was interested in seeing how it worked. They caught a plane together and shared knowledge. By the end of the flight Beck knew the basics of Java and JUnit was born.
As a framework JUnit suits an object-oriented language like Java perfectly as it promotes the testing of individual classes containing single pieces of functionality. Keepin’ it simple and all that. This allows you to write simple tests that can run quickly and are not dependent on other modules. So quicker tests and quicker identification of errors means more efficiency and cheaper solutions. Everyone’s a winner.
Before this, testing was done almost solely by testers and was generally looked down on by programmers. I guess this is still the case to a certain extent today, but JUnit has gone a long way to bridge the gap.
Why is this?
Well, it is written in the programmers own language which is certainly a start. Beck calls testing “emotional certainty”, which is a phrase I am definitely going to use more often. He also talks a lot about the idea of “test-infection” – which is when you see programming in terms of tests first and implementing after, which was a major paradigm shift from how things used to be (the programmers programmed, and the testers tested).
Critics don’t like the fact that TestCase inherits from Assert as it does not follow the standard way to use the inheritance relationship. However Beck is happy about it as it makes JUnit tests more communicative and easier to write – he says that inheritance here is simply a tool to make life easier, not an “abstract philosophical mechanism” and gives the example that it is better to write:
That makes sense, and I like things that make sense and try to be as simple as possible, which is what JUnit tries to do.