O'Reilly logo

TestNg Beginner's Guide by Varun Menon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Migrating from JUnit to TestNG

In case you are migrating from JUnit to TestNG there are certain things that need to be taken care of in your existing test classes and test methods. The following table will help you with making such changes:

Use-case

JUnit-4

JUnit-3

TestNG

Comment

A Test method

@Test

Test-method name starting with "test"

@Test

In case you are migrating from JUnit-4, you just need to change the import. If you are migrating from JUnit-3 annotation all the test methods with @Test

Run before each test method

@Before

Method with name "setup"

@BeforeMethod

Change name and import

Run after each test method

@After

Method with name "cleanup"

@AfterMethod

Change Name and import

Run before each test class ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required