【问题标题】:Java - SWTBot test wizard without workbenchJava - 没有工作台的 SWTBot 测试向导
【发布时间】:2013-01-11 12:19:43
【问题描述】:

我创建了一个 Eclipse 向导,现在我想用 SWTBot 对其进行测试。我已经使用了最终可以工作的 SWTWorkbenchBot,但我现在想在没有 eclipse 工作台的情况下测试向导。这就是为什么我在我的测试类中创建了一个外壳,我想把它放在我的向导页面上,但我所看到的只是一个没有向导页面的空外壳。

所以我创建了一个包含以下代码的新 shell 类:

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 或 JUnitTest 运行,它只会显示一个空的 shell。 这是我的测试类中的代码:

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);
}

【问题讨论】:

    标签: java testing wizard swtbot


    【解决方案1】:

    我认为您的问题源于您从 SWTBot-Thread 创建 GUI 组件这一事实。不过,它们应该由 UIThread 创建。

    通常,您会测试一些插件,该插件会在选择操作后打开向导,例如“新 xyz”。第一步是将您的向导代码放入插件中并注册一个可以启动向导的新操作。那么您可以尝试使用 SWTBot 查找 shell 并执行所需的操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-30
      • 1970-01-01
      相关资源
      最近更新 更多