我认为这并不难。因此,让我们尝试一下:
0.进口
您需要导入三个注释:
import org.junit.After;import org.junit.Before;import org.junit.Test;`
完成接下来的几处更改后,您将不需要
import junit.framework.TestCase;。
1.注释test*
方法
以开头的所有方法都
public void test必须在
@Test注释之前。使用正则表达式可以轻松完成此任务。
2.注释SetUp和TearDown方法
Eclipse生成以下
setUp()方法:
@Overrideprotected void setUp() throws Exception { }必须替换为:
@Beforepublic void setUp() throws Exception { }相同
tearDown():
@Overrideprotected void tearDown() throws Exception { }取而代之
@Afterpublic void tearDown() throws Exception { }3.摆脱 extends TestCase
删除每个字符串文件中恰好出现的一次
" extends TestCase"
4.删除主要方法?
可能有必要删除/重构将执行测试的现有主要方法。
5.将suite()
方法转换为@RunWithClass
根据saua的评论,必须对
suite()方法进行转换。谢谢,索阿!
@RunWith(Suite.class)@Suite.SuiteClasses({ TestDog.class TestCat.class TestAardvark.class})结论
我认为,通过一组正则表达式非常容易,即使它会杀死我的大脑;)



