不带工作台的Java-SWTBot测试向导
我创建了一个eclipse向导,现在我想用SWTBot测试它。我已经使用了SWTWorkbenchBot,它最终可以工作,但是我现在想在没有eclipse工作台的情况下测试这个向导。这就是为什么我在testclass中创建了一个shell,我想把它放在我的wizardpage上,但我看到的只是一个没有wizardpage的空shell 因此,我创建了一个新的shell类,其中包含以下代码:不带工作台的Java-SWTBot测试向导,java,testing,wizard,swtbot,Java,Testing,Wizard,Swtbot,我创建了一个eclipse向导,现在我想用SWTBot测试它。我已经使用了SWTWorkbenchBot,它最终可以工作,但是我现在想在没有eclipse工作台的情况下测试这个向导。这就是为什么我在testclass中创建了一个shell,我想把它放在我的wizardpage上,但我看到的只是一个没有wizardpage的空shell 因此,我创建了一个新的shell类,其中包含以下代码: public static void main(String args[]) { try {
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);
}
在shell类中,它可以工作,我的向导页面会显示出来,但是如果我尝试以SWTBotTest或junitest的形式运行testclass,它只会显示一个空shell。
下面是我的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);
}
我认为您的问题源于这样一个事实,即您正在从SWTBot线程创建GUI组件。但是,它们应该由UIThread创建 通常,您会测试一些插件,这些插件会在选择操作后打开向导,例如“new xyz”。第一步是将您的向导代码放入插件中,并注册一个新操作来启动向导。然后,您可以尝试使用SWTBot查找shell并执行所需的操作