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,
In my opinion, it cannot be that hard. So let's try it:
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;.
test* MethodsAll methods beginning with public void test must be preceded by the @Test annotation.
This task is easy with a regex.
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 { }
extends TestCaseRemove exactly one occurence per file of the string
" extends TestCase"
Probably it's necessary to remove/refactor existing main methods that will execute the test.
suite() method to @RunWithClassAccording 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
})
I think, it's done very easy via a set of regular expressions, even if it will kill my brain ;)