From JUnit to TestNG - migration story

I've joined a new team recently and (to my horror and dismay ;) I've found out that we use JUnit! Well, I just had to do something about it, namely switch to TestNG ASAP! :)

This is a story of migration of one project from JUnit to TestNG. FYI, it was the first time in my life when I performed such a migration (all my previous projects were done with TestNG from the very beginning).

Ok, so let us go! (I took notes while working on the migration).

7:02 start!

7:04 Eclipse installed, Maven project imported

7:07 Eclipse TestNG plugin installed (see

7:10 Scanned through, (in the background all tests run)

7:12 there are only ~40 test methods to convert

7:14 started converting (using TestNG plugin) - looks good, a nice diff view which shows changes introduced by TestNG plugin

7:15 added TestNG to Maven dependencies (scope test)

7:16 Some tests initialize mocks as private fields (taking advantage of the JUnit execution model). TestNG does not work like this, so I need to move them manually to @Before.

7:21 back to IntelliJ IDEA, yeah!

7:24 one test class has not been converted? - why? I have no clue, maybe because it was marked with @Ignored annotation?

7:27 making some changes by hand - moving initialization of mocks to some set-up methods annotated with @BeforeMethod. "Extract field" refactoring (CTRL + ALT + F) helps a lot.

7:32 fixing some remaining stuff - like doubled @Test annotations over test methods which were previously marked as @Ignored

7:34 JUnit removed from Maven dependencies

7:35 mvn clean install - oops, to my surprise the number of tests executed dropped down from 39 to 35, what the hell...? Maybe JUnit counts ignored tests and TestNG doesn't?

7:41 looking into diff to find out what is going on. Along the way fixing minor stuff (e.g. some tests description like "@Ignore("tested method must be refactored")" were not converted)

7:45 Still missing 4 tests - need to check out the original (JUnit) version of code, and run the tests there to see the difference with the current state

7:49 yes, that is it, - TestNG does not bother with reporting ignored (JUnit: @Ignore, TestNG: @Test(enabled=false)) tests - so I'm finished!

7:50 final checks if everything works and looks fine

7:55 grrrr! some SVN #(*$-up! it reports a conflict (pom.xml out of date), but neither svn up nor svn cleanup helps! :(

8:05 someone joined the office (hi Michal!), short break, tea etc.

8:10 all tests passed on Jenkins, migration finished :) No JUnit, all tests written with TestNG.

To sum it up, the plugin helps to converts tests but still you have to see every change to make sure it really works fine and fix some minor stuff (which is boring and irritating, but not hard to do).

Main problems:

  • my lack of Eclipse expertise (in fact, I haven't been using Eclipse for years)
  • SVN issue (wtf?!)


Personally I don't see the added value of using testng, and would rather choose going in the oposite direction, replace testng by junit.

my turn to ask "why?!"

Ah, this is interesting! Could you please explain the reasons for doing so?


Hi Tomek,

Good to hear the conversion went well! Let me know if you think there is anything I can add to the conversion tool to make this kind of job even easier.

Answering the question of another commenter about "why?": I see it more as an investment in the future, which is even more worth doing when the test code base is still small. Once the conversion is done, the tests that get written from that point on can leverage a lot of the advanced features that JUnit doesn't offer (groups, dependencies, multithread, etc...).


Migration too

Once, I migrate test environment from JUnit to TestNG, but with this requirement only the new tests need to be done in TestNG.
UTs are easy to migrate, but integration tests required to change their name, they don't have to end on IT or some other prefix or suffix, which was required by maven integration test plug-in. If you use the same prefix and suffix as JUnit test the maven plug-in will execute the old IT tests twice, once as JUnit and once as TestNG.
So because of the naming issue, the tests didn't migrate to TestNG, which is best testing tool for Java

Why ? I don't see point to

Why ? I don't see point to migrate the project from JUnit to TestNG, what about the team ? do they agree ? do they know how to use JUnit ? and so on ...


hi, thanks for your questions!

1) the team agreed on this - sure, I wouldn't surprise them with a sudden technology change!
2) the team knows how to use TestNG (btw. there are almost on changes in terms of the syntax/API...)

And why? Well, in short - it is worth migrating because TestNG offers a lot of goodness for integration/end-to-end tests which JUnit doesn't (but also some nice features useful in unit tests).

In few days I will post a short presentation which I used to present TestNG to my teammates and discuss the idea of migration. Maybe it will answer your "why?" question. :)

Can u pls elaborate more on this


can u pls illustrate this with simple example,because i am getting stuck at the point where
I have both testng and junit configured at my end.
1.I have to migrate this junit class to testng without changing the source code.
2.Have made the changes in the testng tag.(

3.What exact steps do i need to perform for the migration.

Please comment using