Use SWTBot
使用SWTBot,可以通过写JUnit测试代码为Eclipse plug-in开发做自动化测试。参考了这篇文章。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| package swtbot_test;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.swt.finder.SWTBotAssert; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith;
@RunWith(SWTBotJunit4ClassRunner.class) public class SwtTest {
private static SWTWorkbenchBot bot;
@BeforeClass public static void setUpBeforeClass() throws Exception { bot = new SWTWorkbenchBot(); bot.viewByTitle("Welcome").close(); }
@Test public void testNewWizard() throws Exception { bot.menu("File").menu("New").menu("Project...").click(); SWTBotShell shell = bot.shell("New Project"); shell.activate(); bot.tree().getTreeItem("Abc plug-in Development").getNode("").select();
SWTBotAssert.assertEnabled(bot.button("Next >")); bot.button("Next >").click();
bot.text().setText("Test1");
SWTBotAssert.assertEnabled(bot.button("Finish"));
bot.button("Finish").click();
shell = bot.shell("Open Associated Perspective?"); shell.activate(); bot.button("Yes").click();
}
@AfterClass public static void tearDownAfterClass() throws Exception { if(bot!=null) { bot.sleep(2000); } } }
|