デザインを変えました
気分転換。
ログ編
UrumaとUrumaアプリとUruma以外のUrumaに依存しないプラグイン(オレオレプラグイン)からlog4jの設定を共通で利用したい。log4jを利用するプラグインは設定ファイルを一意にしたいため。
でも、Uruma、Urumaアプリと、オレオレプラグインはlog4jの設定を共用できません。各プラグインロードするlog4jのクラスが異なるため。
ということで、Urumaからapache log4jと commons logingを別プラグインとして切り出し、各プラグインから参照するようにする。
あれ、commons logingのクラスを認識しない?!各プラグインの依存設定も、commons logingのExported Packagesも正しいのになぁ。しょうがないので、commons logingをslf4jに置き換え。うまくいった。
Uruma、Urumaアプリではニーズがない対応と思うのでコミットはしないでおく。プラグインを分割すると配布や管理がややこしくなるし、ユーザの稼働失敗の確率も高くなるしね。
SWTとEclipseの両方に対応したTestTool SWTBot
SWTとEclipseの両方に対応したTestToolSWTBotがおもしろそう。バージョンも最近1.0がリリースされています。JUnitのようなユニットテストと、操作に基づいた機能テストの両方を行えます。
使い方がなぜかリリースノートに記載されています。
サンプルコードを張っておきます。雰囲気がつかめると思う。
操作系のサンプル
package net.sf.swtbot.eclipse.spy; import net.sf.swtbot.eclipse.finder.SWTEclipseBot; import net.sf.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor; import net.sf.swtbot.wait.Conditions; import net.sf.swtbot.widgets.WidgetNotFoundException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; /** * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> * @version $Id$ */ public class PlayBackThread extends Thread { private static final Log log = LogFactory.getLog(PlayBackThread.class); /** the e */ private final Event e; public PlayBackThread(Event e) { super("PlayBackThread"); this.e = e; } public void run() { log.debug("running..."); try { perform(); } catch (Exception e) { e.printStackTrace(); } } /** * @throws WidgetNotFoundException */ private void perform() throws Exception { Display display = e.display; SWTEclipseBot bot = new SWTEclipseBot(); createJavaProject(bot); createJavaClass(bot); Thread.sleep(1000); SWTBotEclipseEditor editor = bot.editor("HelloWorld.java"); Thread.sleep(1000); editor.notifyKeyboardEvent(SWT.CTRL, '.'); editor.quickfix("Add unimplemented methods"); editor.navigateTo(7, 0); editor.autoCompleteProposal("sys", "sysout - print to standard out"); editor.typeText("\"Hello World\""); editor.navigateTo(3, 0); editor.autoCompleteProposal("main", "main - main method"); editor.typeText("new Thread (new HelloWorld ());"); if (true) return; editor.notifyKeyboardEvent(SWT.CTRL, '2'); editor.notifyKeyboardEvent(SWT.NONE, 'L'); editor.notifyKeyboardEvent(SWT.NONE, '\n'); editor.typeText("\n"); editor.typeText("thread.start();\n"); editor.typeText("thread.join();"); editor.quickfix("Add throws declaration"); editor.notifyKeyboardEvent(SWT.NONE, (char) 27); editor.notifyKeyboardEvent(SWT.NONE, '\n'); editor.notifyKeyboardEvent(SWT.CTRL, 's'); editor.notifyKeyboardEvent(SWT.ALT | SWT.SHIFT, 'x'); editor.notifyKeyboardEvent(SWT.NONE, 'j'); try { Thread.sleep(1000); } catch (InterruptedException e1) { e1.printStackTrace(); } } /** * @param bot */ private void createJavaClass(SWTEclipseBot bot) throws Exception { bot.menu("File").menu("New").menu("Class").click(); bot.shell("New Java Class").activate(); bot.textWithLabel("Name:").setText("HelloWorld"); bot.textWithLabel("Package:").setText("com.helloworld"); implementsInterface(bot, "java.lang.Runnable"); bot.checkBox("Inherited abstract methods").click(); bot.button("Finish").click(); } /** * @param bot */ private void implementsInterface(final SWTEclipseBot bot, String interfaceClass) throws Exception { bot.button("Add...").click(); bot.shell("Implemented Interfaces Selection").activate(); bot.textWithLabel("Choose interfaces:").setText(interfaceClass); bot.waitUntil(Conditions.tableHasRows(bot.table(), 1)); bot.button("OK").click(); bot.shell("New Java Class").activate(); } /** * @param bot */ private void createJavaProject(net.sf.swtbot.SWTBot bot) throws Exception { bot.menu("File").menu("New").menu("Java Project").click(); bot.shell("New Java Project").activate(); bot.textWithLabel("Project name:").setText("MyProject"); bot.button("Finish").click(); } }
ユニット系のサンプル
package net.sf.swtbot.widgets; import net.sf.swtbot.SWTBot; import net.sf.swtbot.finder.AbstractSWTTestCase; /** * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> * @version $Id$ */ public class SWTBotButtonTest extends AbstractSWTTestCase { private SWTBot bot; public void testFindsButtons() throws Exception { assertEquals("One", bot.button("One").getText()); assertEquals("Select Listeners", bot.button("Select Listeners").getText()); } public void testClicksButtons() throws Exception { SWTBotShell shell2 = null; try { SWTBotButton button = bot.button("Set/Get API"); button.click(); shell2 = bot.shell("Button Set/Get API"); assertNotNull(shell2.widget); assertEquals("Button Set/Get API", shell2.getText()); } finally { if ((shell2 != null) && (shell2.widget != null)) shell2.close(); } } public void testFindsBackgroundColor() throws Exception { assertNotNull(bot.button("One").backgroundColor()); } public void testFindsForegroundColor() throws Exception { assertNotNull(bot.button("One").foregroundColor()); } protected void setUp() throws Exception { super.setUp(); bot = new SWTBot(); bot.tabItem("Button").activate(); } }
参考
SWTBotを入れてみた その1
Eclipse Update URL: http://swtbot.sourceforge.net/update-site/
- Preferncesは変わらず。
- Viewは1つ増えた。でも何も表示されない、何も入力できないww
- Run Configureationsは SWTBot Testが増えた。