简体   繁体   中英

Migrating from Junit to TestNG

I need to migrate a bunch of test scripts from Junit to TestNG , So is there any utility or a runner does TestNG provides to run Junit test scripts ? also I am currently using Maven .

If possible Can someone share the snippet on how to do it .

The official document for Migrating from Juit to TestNG can be found here . Please have a look. You can also check this for better understanding.

I understand that it is a very old post, but I hope this would be useful if anyone is looking to migrate to TestNG.

I have a spring application and my JUnit tests uses different runners and tags like - SpringJUnit4ClassRunner - PowerMockRunner - EasyMockRunner - @ContextConfiguration.

Junit works with @RunWith tag where as TestNG requires extending classes AbstractTestNGSpringContextTests(for @ContextConfiguration), PowerMockTestCase(for PowerMockRunner), ..etc. Though there were multiple options provided(extending, configuration, other annotations) in some cases, some of the options didn't work and extending only worked. If the test class requires extending it may not work for some tests as the test might be already extending another base class and you need to refactor the tests and it may not be worth.

My 2 cents is that JUnit5 has some of the missing Junit4 features of TestNG and see if that solves the problem before jumping to migrating to TestNG.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM