InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

JUnit Still Not Dead

Posted by Craig Wickesser on Aug 14, 2008

Sections
Process & Practices,
Development,
Operations & Infrastructure
Topics
Unit Testing ,
Release ,
Java
Tags
TestNG ,
JUnit
JUnit is a unit testing framework for Java which has been around for years. It was originally developed by Kent Beck and Erich Gamma and is now maintained by the community which has recently released JUnit 4.5. In the many years that JUnit has been around numerous projects in the xUnit family have been spawned including: Even with years of development effort and usage on countless software projects around the world some continue to wonder if JUnit's fate is nearing its end. Often times when someone (or some group) of people begin to doubt the long term existence of a software project they will rely on web page viewing statistics. Just this week Mike blogged about the declining "interest" in JUnit based upon search engine results. Although he concludes by stating he doesn't believe JUnit is dead there seems to be some inclination that perhaps JUnit is being surpassed.  One reason might be that as newer and better software practices evolve more and more developers catch on to them. Unit testing is certainly important and widely accepted, however, behavior driven development, mock objects and newer-featured unit testing frameworks are standing in the spotlight.

One framework which is often compared to JUnit is TestNG, a testing framework inspired by JUnit. Michael Minella provides a brief but useful comparison between JUnit and TestNG.

Feature JUnit TestNG
User Defined Life Cycle check check
Test Organization (groups, etc)   check
Distributed Test Execution   check
Parallel Test Execution   check
Data Driven Tests   check
Dependency Testing   check
IDE Integration check check
Ant Integration check check
Maven Integration check check
Domain Specific Extensions (Database, HTTP, etc) check  
Active Community check check
source


To summarize his thoughts, JUnit has been adopted and extended more so than TestNG, however, TestNG seems to offer more functionality and has the ability to invoke JUnit tests, making it a tempting choice in testing frameworks.

In conclusion, JUnit may not be in the spotlight as much as it was a year ago, but is it really walking closer towards the 'bright light'? What do you think, what does the future have in store for JUnit?

22 comments

Watch Thread Reply

I do think TestNG is better by 许 晓斌 Posted
*infamous*????? by Artur Karazniewicz Posted
Re: *infamous*????? by Michael Stachel Posted
Re: *infamous*????? by Mark Levison Posted
Re: *infamous*????? by Artur Karazniewicz Posted
Re: *infamous*????? by James Williams Posted
Re: *infamous*????? by Sean Kennedy Posted
Assumptions based on web statistics??? by Guillaume Bertrand Posted
JUnit is far from dead by Michael Minella Posted
Re: JUnit is far from dead by craig w Posted
Re: JUnit is far from dead by Kurt Christensen Posted
Re: JUnit is far from dead by Bernd Eckenfels Posted
Re: JUnit is far from dead by Sai Venkatakrishnan Posted
Using TestNG by Mileta Cekovic Posted
infamous? by Etienne L Posted
xUnit as "The Camel's Nose" by Paul Nelson Posted
TestNG by Joshua Partogi Posted
Re: TestNG by James Williams Posted
Re: TestNG by Morten Hattesen Posted
Re: TestNG by Robin de Silva Jayasinghe Posted
Junit ...infamous... by Amin Mohammed-Coleman Posted
Search statistics are not the way to measure a mature tool popularity by Fernando Lozano Posted
  1. Back to top

    I do think TestNG is better

    by 许 晓斌

    I like the features of TestNG, but of course it's a little more complicated.

  2. Back to top

    *infamous*?????

    by Artur Karazniewicz

    "JUnit has recently released version 4.5 of the infamous Java testing framework"





    "*infamous*"? Did the Author smoke something Yesterday?.. Since when JUnit is infamous? Did I miss something?





    Also above comparison of JUnit and TestNG is little bit unfair, IMHO.





    IDE integration of JUnit is usually far, far ahead than TestNG. It usually comes with Your IDE, right there, build in, with all the goodies. I can simply pres my favurite keystroke and have test stub done for me. I can see reference for all my test, every coverage tool comes with support for JUnit, every CI server comes with integration fo JUnit...





    Second, there are *gazilions* of plugins and JUnit integrations basically for everything You could even think about.




    Last but not least - xUnit is supposed to be a *simple* tool. Just do the things it's supposed to do - Unit Test Your code. Lots of extra features TestNG has, for 80% of usages, are useless. Or at least I lived without them for last ten Years.





    Artur

  3. Back to top

    Assumptions based on web statistics???

    by Guillaume Bertrand

    Correct me if I am wrong, but the only assumptions to say that JUnit is declining is that less people are visiting the JUnit website than the TestNG one?



    JUnit is a mature framework, that many people use and that comes integrated in your IDE (as Artur rightly pointed out). I, for one, have been using JUnit for many years and I don't think I visited the website more than once (twice if you include today's visit for the sake of my argument); I just update my Eclipse regularly and JUnit gets updated along the way!



    If need be, I am happy to visit the JUnit website every time I run a test :)

  4. Back to top

    Re: *infamous*?????

    by Michael Stachel

    ... Lots of extra features TestNG has, for 80% of usages, are useless. Or at least I lived without them for last ten Years.


    This is the same kind of statement in the opposite direction as you did with asking whether the author did smoking something. So I answer you: "Have you lived behind a rock the last ten years or is your code being tested only "Hello World" stuff? :-)

    I recommend you take a look at TestNG and then come up with something more substantial. It is good that you defend your choice but without making claims which proves nothing.

    Michael

  5. Back to top

    Re: *infamous*?????

    by Mark Levison

    JUnit is a unit testing tool and it focuses on doing a good job of that.


    TestNG - wants to be a unit testing tool and a whole lot more.


    Neither is perfect, both make useful tools. Zealotry doesn't serve any of us well. I keep both tools in my arsenal and am agnostic as to which one I use.


    Also contrary to the belief of some Junit is still actively developed and evolving.


    Minor nit with the article: It can be argued that Dependency testing etc are not unit testing and hence the reason that its been left out of JUnit.


    Also the claims that Cedric has made with respect to his influence of JUnits adoption of the NUnit like attributes have turned off more than a few members of the community.

  6. Back to top

    JUnit is far from dead

    by Michael Minella

    Although in my blog post I said that I believe TestNG was a better framework, it's far from the leader regarding market share. JUnit still has the lion's share of the market. Between tool integration, developer familiarity and the fact that test driven development is still not as dominant as it should be, it will be a while before other tools gain enough traction to threaten JUnit's market dominance.

  7. Back to top

    Re: JUnit is far from dead

    by craig w

    @Artur
    I used "infamous" to indicate that JUnit is so widely known. Quite often if you ask a Java developer about unit testing JUnit is at least one of the tools they use or have heard of. And the comparison between JUnit and TestNG was meant to provide "brief" overview, not saying it was perfect or completely unbiased.

    It is true that there are lot of extensions (I did make a reference to it near the end of the article).

    @Mark
    I agree I thinking having both in your tool belt is a good idea, as a developer, we should be open minded and adopt whatever works best for the work we are doing.

  8. Back to top

    Re: JUnit is far from dead

    by Kurt Christensen

    Nitpick FYI: I think what Artur was picking on was that you meant to say "famous" and not "infamous", which many, many people do inadvertently. From dictionary.com:



    in·fa·mous

    –adjective

    1. having an extremely bad reputation: an infamous city.

    2. deserving of or causing an evil reputation; shamefully malign; detestable: an infamous deed.

  9. Back to top

    Re: *infamous*?????

    by Artur Karazniewicz

    Michael. To answer Your question. Yes I looked at TestNG - it's nice, neat and funny. But how did its existence made JUnit "*infamous*"? You know, writing unit tests is about testing Your code, not testing brand new testing framework itself.




    Artur

  10. Back to top

    Using TestNG

    by Mileta Cekovic

    I am using TestNG for several years. Enough said.

  11. Back to top

    Re: JUnit is far from dead

    by Bernd Eckenfels

    Dont spent too much time talking about testing - use it to write test cases.

  12. Back to top

    Re: JUnit is far from dead

    by Sai Venkatakrishnan

    Junit is a solid good framework. It delivers what is needed and everything else is an add on. I think Junit will be here to stay for a pretty long time. Junit is mainly used to drive the design so in that point of view I think that any tool which lets me do that job of driving design and lightweight is good. TestNG's feature rich but that mustn't divert us from the primary use of these tools.

  13. Back to top

    infamous?

    by Etienne L

    I don't see the need to call JUnit "infamous" to prove your point Wickesser. Btw, your analysis and "conclusion" is a little bit light for this kind of statement. Wouldn't it be better to compare TestNG to Junit and let the reader build their opinion? And I am not talking about a list of bullet points: a real case example would have better served your demonstration.

  14. Back to top

    xUnit as "The Camel's Nose"

    by Paul Nelson

    There is one major benefit that I think the article misses, though it is a companion benefit to one mentioned. I have been studying both Erlang and Objective-C lately in my spare time, and having an xUnit framework (EUnit and OCUnit respectively) provides a familiar tool with which to poke and prod these new (to me) territories.

    It's very cool having experience in a tool transfer so seamlessly to other languages, and has significantly reduced my learning curve for new programming languages, frameworks and libraries. I hope xUnit's ubiquity insures it's long-term success (I think it will)... at least until something else becomes as pervasive.

  15. Back to top

    TestNG

    by Joshua Partogi

    I like TestNG better because it is easier for me to exclude or include tests that I want to run by setting it up in testng.xml.

  16. Back to top

    Re: *infamous*?????

    by James Williams

    I couldn't agree more. I've used TestNG on a Seam project and found the IDE integration lacking. JUnit has served me well and with the use of annotations that came with version 4 I quickly untied my Seam tests from TestNG and used JUnit.

    James
    www.jameswilliams.com.au

  17. Back to top

    Re: TestNG

    by James Williams

    JUnit provides this too with the @Ignore annotation. TestNG does give you the ability to have different sets of tests (fast and slow for example) but it's tool support in Eclipse is shocking. The plugin does not reliably refresh and runs the tests based on a generated xml file that can get out of sync with the actual state of the code. I've spent time wondering why my changes don;t seem to make a difference to then realise I needed to clean my project. And don;t get me started about not being able to run a single test method in a test class. :-)


    James

    www.jameswilliams.com.au

  18. Back to top

    Re: TestNG

    by Morten Hattesen

    As of JUnit 4 it is quite easy to disable (exclude) tests, by adding the @Ignore annotation on @Test methods (or as of version 4.3, on entire JUnit classes).

    I find that easier than fiddling around in xml files.

  19. Back to top

    Junit ...infamous...

    by Amin Mohammed-Coleman

    I'm probably going to say the same that others have said. JUnit is the most popular Unit testing framework and I have worked in various companies and they all use JUnit. At the end of the day it's all about testing code that you have written and if JUnit works for you then thats ok. I personally don't care as long as there is a mature and solid framework that ensures proper testing for my code.

    By the way..JUnit is certainly not infamous...

  20. Back to top

    Search statistics are not the way to measure a mature tool popularity

    by Fernando Lozano

    Has anyone wondered that maybe web searches and web site accesses for JUnit may be just the result of it being included by default with most IDEs? And the fact there are so many books and third-party articles that cover JUnit usage? People simply doesn't to "go to the source" for JUnit!

  21. Back to top

    Re: TestNG

    by Robin de Silva Jayasinghe

    Additionally JUnit has got nice extension points for manipulating the set of tests to be run. Just extend Filter or Sorter. Especially when you decorate your testcases with custom annotations they become very powerful. :)

  22. Back to top

    Re: *infamous*?????

    by Sean Kennedy

    "JUnit has recently released version 4.5 of the infamous Java testing framework"

    perhaps after this article JUnit 4.6 will become infamous by spawning a google search for JUnit every time a unit test passes

    then everyone will know how wonderful JUnit is

Educational Content

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.