wood burning stoves*
The moose likes Testing and the fly likes most important feature in TestNG Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "most important feature in TestNG" Watch "most important feature in TestNG" New topic
Author

most important feature in TestNG

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30076
    
149

I'm curious what the authors (or anyone else with experience in TestNG) consider to be the most important few features in TestNG that is not in JUnit 4.0. Most articles, just hash through the differences between TestNG and JUnit 3.8.

From reading the book, the concurrency testing support seems useful if you are working on a threaded application.

If test groups are your answer, what do you consider the second most important feature that is not in JUnit 4.0? (because groups have been well discussed this week)


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Hani Suleiman
author
Greenhorn

Joined: Nov 18, 2007
Posts: 22
Probably nothing exciting here unfortunately, no secret hidden features!

My personal 'easy' favourites are two things (related to groups, boringly enough): stateful tests, and dependencies.

I cant imagine writing non-stateful tests. I don't know how people manage without them. When testing a blahManager for example, do you really create a new one every time? How about db connections? Environment setup? Spring initiatlization?

Dependencies likewise mean you can have tests that build on other tests in a meaningful way. The send/receive example in another thread here highlights that pattern. Likewise, depending on named initialization groups means you can express such concepts as 'this test needs db connectivity, a jms provider, and a servlet engine'.

I'll also name a more 'hidden' neat feature, which is the object factory concept. The interesting thing here is that this allows you to control test instantiation. Why is this useful? Well, if you can control creating the test, you can do all sorts of funky stuff before returning the instance to testng. You could return a bytecode instrumented version, you could use Spring or Guice to inject its dependencies in, all sorts of craziness!
Cedric Beust
author
Ranch Hand

Joined: Oct 12, 2004
Posts: 46
Hi Jeanne,
Originally posted by Jeanne Boyarsky:
I'm curious what the authors (or anyone else with experience in TestNG) consider to be the most important few features in TestNG that is not in JUnit 4.0. Most articles, just hash through the differences between TestNG and JUnit 3.8.

From reading the book, the concurrency testing support seems useful if you are working on a threaded application.

If test groups are your answer, what do you consider the second most important feature that is not in JUnit 4.0? (because groups have been well discussed this week)


Since you excluded groups, I'll have to name Data Providers as my favorite feature #2, and it seems to be a feeling widely shared by TestNG users.

For readers not familiar with Data Providers, here is an example:

@DataProvider
public Object[][] data() {
return new Object[][] {
new Object[] { "Lexus", "Red" },
new Object[] { "Toyota", "Blue" },
}
}

@Test(dataProvider = "data")
public void verifyMakeAndColor(String carModel, String color) {
// will be invoked first with ("Lexus", "Red") and then with
// ("Toyota", "Blue")
}

This simple construct allows you to define all kind of interesting tests where the business logic of your test doesn't change but the data does.

Since the Data Provider is a Java method, it can get its data either directly from the source (as shown above) or from many different locations: properties file, flat file, XML file, Excel spreadsheet (very popular), a database or even the network.

TestNG users have been extremely creative over the years with this feature. For example, someone posted the code for a Data Provider that would read a configuration file based on the test method it's about to feed data to, which I found very clever.

We have an entire section on Data Provider in the book and we have barely scratched the surface of what it can do...

Does this answer your question?

--
Cedric
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30076
    
149

Thank you both for the reply.

Hani: I wasn't looking for secret hidden features. Just a personal opinion from two people who know TestNG really well!

Cedric: Yes, this answers my questions. I only excluded groups because they've been discussed extensively already. And I kind of figured they would be your favorite and wanted to get a more interesting answer
 
wood burning stoves
 
subject: most important feature in TestNG
 
Similar Threads
Do you know other testing tool like JUnit ??
Sample Java Program and codes for TestCase
TestNg or Junit
Naming convention for methods with JUnit
JUnit Testing