0
我創建了一個eclipse嚮導,我現在要用SWTBot測試它。我已經使用了SWTWorkbenchBot,它終於可以工作,但我現在不想在Eclipse工作臺上測試嚮導。這就是爲什麼我在我的測試類中創建了一個shell,我想把它放在我的wizardpage上,但是我只能看到,是一個沒有我的wizardPage的空殼。Java - 沒有工作臺的SWTBot測試嚮導
所以我創建了一個新的外殼類,其中包括該代碼:
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);
}
隨着殼類它的作品,我wizardpage被證明,但如果我嘗試運行我的TestClass作爲SWTBotTest或JUnitTest它不會顯示我什麼都不是空殼。 下面是我的TestClass代碼:
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);
}