SWTBotでテストしたい日食ウィザードを作成しました。私はすでにSWTWorkbenchBotを使用しましたが、これは最終的に機能しますが、Eclipseワークベンチなしでウィザードをテストしたいと思います。そのため、ウィザードページに配置したいテストクラスでシェルを作成しましたが、表示されたのは、wizardPageのない空のシェルだけでした。
そこで、このコードを含む新しいシェルクラスを作成しました。
public static void main(String args[]) {
try {
Display display = Display.getDefault();
HorrorShell shell = new HorrorShell(display);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the shell.
*
* @param display
*/
public HorrorShell(Display display) {
super(display, SWT.SHELL_TRIM);
setLayout(new FillLayout());
createContents();
}
/**
* Create contents of the shell.
*/
protected void createContents() {
setText("SWT Application");
setSize(450, 300);
ManualSettingsWizardPage page = new ManualSettingsWizardPage();
page.createControl(this);
}
シェルクラスが機能すると、ウィザードページが表示されましたが、テストクラスをSWTBotTestまたはJUnitTestとして実行しようとすると、空のシェル以外は表示されません。これが私のテストクラスのコードです:
private ManualSettingsWizardPage wizard;
private SWTBotShell botShell;
private Shell shell;
private Display display;
private SWTBot bot;
@Before
public void setUp() {
botShell = new SWTBotShell(shell);
bot = new SWTBot();
wizard = new ManualSettingsWizardPage();
display = Display.getDefault();
shell = new Shell(display);
shell.open();
shell.layout();
}
@Test
public void bot() throws Exception {
bot = botShell.bot();
shell.setBounds(200, 200, 400, 400);
shell.setLayout(new FillLayout());
wizard.createControl(shell);
}