Manoj Govindan
Manoj Govindan

Reputation: 74765

Moving from JUnit to TestNG: how to convert @SuiteClasses?

I'm converting a bunch of test cases written for use with JUnit 4+ to use TestNG instead. I found that test class level annotations are mostly similar and can be replaced easily (for e.g. @Before => @BeforeMethod). However test suites are trickier to convert. For e.g. I have a bunch of test suites designed to run using JUnit's @SuiteClasses annotation:

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({ Foo.class, Bar.class, Baz.class, subpackage.AllTests.class })
public class AllTests {}

What is the best way to convert such classes to suites recognized by TestNG? Should I write a script to generate corresponding some_suite.xml for each of these classes? Is there a better way?

Upvotes: 2

Views: 2454

Answers (1)

Cedric Beust
Cedric Beust

Reputation: 15608

You can either create a .xml file (which I recommend you do since it will make your life easier down the line, and eventually, that .xml will contain your entire test suite), or you can use the TestNG API, which is pretty straightforward. Here is the relevant documentation.

Upvotes: 1

Related Questions