Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 165331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:54:08+00:00 2026-05-11T11:54:08+00:00

I have a bunch of JUnit 3 classes which extend TestCase and would like

  • 0

I have a bunch of JUnit 3 classes which extend TestCase and would like to automatically migrate them to be JUnit4 tests with annotations such as @Before, @After, @Test, etc.
Any tool out there to do this in a big batch run?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:54:08+00:00Added an answer on May 11, 2026 at 11:54 am

    In my opinion, it cannot be that hard. So let’s try it:

    0. Imports

    You need to import three annotations:

    import org.junit.After; import org.junit.Before; import org.junit.Test;` 

    After you’ve made the next few changes, you won’t need import junit.framework.TestCase;.

    1. Annotate test* Methods

    All methods beginning with public void test must be preceded by the @Test annotation. This task is easy with a regex.

    2. Annotate SetUp and TearDown methods

    Eclipse generates following setUp() method:

    @Override protected void setUp() throws Exception { } 

    Must be replaced by:

    @Before public void setUp() throws Exception { } 

    Same for tearDown():

    @Override protected void tearDown() throws Exception { } 

    replaced by

    @After public void tearDown() throws Exception { } 

    3. Get rid of extends TestCase

    Remove exactly one occurence per file of the string

    ' extends TestCase' 

    4. Remove main methods?

    Probably it’s necessary to remove/refactor existing main methods that will execute the test.

    5. Convert suite() method to @RunWithClass

    According to saua’s comment, there must be a conversion of the suite() method. Thanks, saua!

    @RunWith(Suite.class) @Suite.SuiteClasses({   TestDog.class   TestCat.class   TestAardvark.class }) 

    Conclusion

    I think, it’s done very easy via a set of regular expressions, even if it will kill my brain 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 test classes, both extend TestCase . Each class contains a bunch
I have a bunch of classes I want to rename. Some of them have
Have a bunch of classes which I need to do serialize and deserialize from/to
We have a bunch of redirects in our Apache configuration. I would like to
We have bunch of autogenerated classes which are mostly Axis2 stubs, skeletons etc. For
We have a bunch junit tests in our current project. Essentially we are looking
I have a Junit process that runs a bunch of data integrity tests every
We have bunch of Domain Entities which should be rendered to an html format,
We have a bunch of tests in a maven2 project and build with cruisecontrol.
lets say I have bunch of hyperlinks. When link is clicked, I'd like an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.