Wednesday, May 7, 2008

Running TestNG on NetBeans 6.0

TestNG is a great testing framework. And it's much more powerful than JUnit.
The problem for NetBeans 6.0 users is that there is no plugin for TestNG. I've spend a lot of time before I managed to run TestNG in a simple way. After some time I've figured out that the main obstacle is that NetBeans does not recognizes TestNG classes as test classes. And this was the key to success.
I've successfully run the tests using its command line and NetBeans Run feature. And it was done on the NetBeans Java SE bundle (the simplest one).
So, here are the simple steps to launch TaestNG on NetBeans:
  1. Project Properties -> Libraries. Compile-time libraries must contain testng-XXX.jar (where XXX is your TestNG version). Also Run-time libraries must contain the path to your compiled tests (if you put your test to default test directory, than the path to compiled tests should be build/test/classes).
  2. Create TestNG xml file(s). There are instructions how to build such file in the framework site. E.g. create testng.xml and put it in the project root.
  3. Project Properties -> Run. Create new configuration. You may name is testNG ;) Enter org.testng.TestNG as the Main Class. Put your TestNG xml file(s) as Arguments. Multiple xml files should be separated by space. Enter your project directory as Working Directory.
Congratulations! Now you can run your TestNG tests through NetBeans Run feature.

P.S. Even if there will be only one person on Earth who saves a few hours this post worth its writing.

6 comments:

Anonymous said...

Thanks! It's exactly what I was looking for.

Максим Шостак said...

Hi.

Thank you for this post.

The problem is that NetBeans do not recompile classes in 'test' folder when you 'Build Main Project' or even 'Clean' it before.

How did you eliminated this?

Максим Шостак said...

(I just subscribed for follow-up comments)

Andriy said...

Hi Maksym!

I've also noticed the same problem :)
I've found the following workaround in current NetBeans version (6.5): add 'test' folder to "project" > "properties" > "sources" > "source package folders" (initially it was at "test package folders").
Not sure whether there is such option in version 6.0.

Sravan Kumar Sarraju said...

Thanks mate..ur blog saved lot of time..!

generic cialis said...

In principle, a good happen, support the views of the author