TestNG 5.6 and Junit 4.4 : which framework you will choose for unit testing?

Add a comment February 29th, 2008

As we all know JUnit is the most famous unit testing framework. Nobody needs any type of introduction for this small and easy framework. Most of the developers are using this as their unit testing framework in their day to day development life. And can I ask one question? Do you know TestNG? a unit testing framework which is named as ‘Next Generation test ing tool’. Here is a small comparison on these two unit testing frameworks.

  TestNG Version 5.6   JUnit  Version 4.4
1 Extensive annotation support 1 Supports Annotations but not that much rich as TestNG
2 Flexible test configuration in an external XML file. 2 Configuration is less and no XML file configuration at all.
3 External configuration gives more flexibility. 3 Less configuration makes it more easy and really fast to create :)
4 Support for data-driven testing (with @DataProvider). 4 We have to integrate with EasyMock for Mock object testing
5 Support for parameters using @Parameters 5 No such type of annotations
6 Allows distribution of tests on slave machines. 6 NA
7 Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc…). 7 Cant defeat JUnit in this matter. It has a lot of supporting tools and plugins.
8 Embeds BeanShell (scripting)  for further flexibility. 8 JUnit dont have this feature at all.
9 Default JDK functions for runtime and logging (no dependencies). 9 I dont aware of logging support in JUnit.
10 Dependent methods for application server testing. 10 NA
11 Creates a small HTML report at eash time of testing. Which will display the passed/failed tests and errors. It gives the XML output for testing also. 11 JUnit also creates the test report in XML form. But it will not create an HTML form with passed/failed testnames at each test run. But we can create a very useful JavaDoc Style report for entire JUnit testing
12 We dont need a specific name for setup and tearDown. We can make any method/ any number of methods that works on start up 12 Same in Junit also.
13 Here we can create Groups, Suites, etc and it also gives more annotations like
@After/BeforeSuite.
@After/BeforeGroup.
@After/BeforeClass.
@After/BeforeMethod
etc
13 @After/Before works in methods and @After/BeforeClass will work with classes. But no groups or suites.
14 No annotation like @Ignore. But we can ignore through XML congiurations. 14 @Ignore annotation is there for ignoring a method.
15 Dependancy of previous methods can be managed easily 15 Methods dependancy handling between each test methods is not possible easily.
16 Option to run failed tests only/ last test only in the IDE 16 We have to select and run each methods which are failed
17 No AssertThat method support 17 It gives a method AssertThat that is very much flexible for giving a Business type result message for the tests.
18 Using ‘ExpectedExceptions in @Test Annotation’ we can expect some exceptions in the test methods and thus the method will be success. 18 We can use (expected = Exception.class) in the @Test annotation

Conclusion

If you are a very busy programmer and want very little time to spend on testing the code then go for JUnit. It is giving enough support for that. But you need a good testing and more configurable options for each test cases then choose TestNG. The depeneded methods are also can make work on TestNG very easily.

Digg This
Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

Popularity: 1% [?]

Bookmark this on BuzzURLBookmark this on BuzzURL Post to TwitterTweets for this web page Bookmark this on FC2 Bookmark newsing it! Choix it! Add to Google Bookmark Bookmark this on Delicious Digg This

Related posts:

  1. Wink – A framework for RESTful web services from Apache Apache Wink 1.0 is a complete Java based solution for...

Related posts brought to you by Yet Another Related Posts Plugin.

  1. February 29th, 2008 at 20:43 | #1
    Cedric

    FYI, Ignore is supported in TestNG with @Test(enabled=false). And also by excluding groups that your method belongs to.

  2. March 3rd, 2008 at 05:16 | #2

    Thanks Cedric. Thanks for the Info.

  3. March 3rd, 2008 at 15:11 | #3
    Eric Jablow

    I’ve seen but never used Log4Unit, hosted at http://www.openfuture.de/Log4Unit/.

  4. March 3rd, 2008 at 21:37 | #4

    Just a couple of things:

    1/ @ExpectedExceptions is deprecated for a long time. Instead you should be using @Test(expectedExceptions= { /* class list */ })

    2/ TestNG has introduced the notion of skipped tests. These are neither failures, nor passed, but rather tests that were supposed to run but due to some “dependency” error (being a configuration failure or a test dependency failure) they were not run. This will lead to cleaner reports.

    3/ You can use Hamcrest support for literate assertions. JUnit support is limited in this direction too, so finally you’ll have to use Hamcrest.

    bests,

    ./alex

    .w( the_mindstorm )p.
    TestNG co-founder
    EclipseTestNG Creator

  5. March 4th, 2008 at 01:28 | #5
    Hayato Ijuin

    Eclipse allows to run failed tests only or last test only for JUnit. I don’t know if it’s a Eclipse’s peculiarity or a JUnit feature, though.

  6. March 4th, 2008 at 04:25 | #6

    @Eric @Hayato
    Thanks for the info friends

  7. February 23rd, 2009 at 18:57 | #7

    @Alex
    Thank you very much Alex for giving your Precious Time for us.

  1. |
    March 5th, 2008 at 05:07 | #1

    [...] and JUnit are 2 of the most popular testing frameworks in the market at the moment. I found this article comparing both frameworks interesting and would like to share with all of you. On top of that, I would like to mention a nice [...]

  2. |
    March 7th, 2008 at 23:39 | #2

    [...] Which Unit Test Framework will you use – here [...]

Comments feed