0

所以我正在用 SWTbot 测试一个 Eclipse 插件,但我没有得到我期望的结果——当我减少测试时,结果发现问题不在于机器人,而在于我复制的一些代码跨越程序的另一部分(功能齐全的地方)

以下代码...

@RunWith(SWTBotJunit4ClassRunner.class)
public class Tests {

    private static SWTWorkbenchBot bot;

    @BeforeClass
    public static void beforeClass() throws Exception {
        bot = new SWTWorkbenchBot();
        bot.viewByTitle("Welcome").close();
    }

    @Test
    public  void maybeThisWillWork(){
        IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        System.out.println("A");
        IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
        System.out.println("B");
    }

    @AfterClass
    public static void sleep() {
        System.out.println("In the sleep function");
        bot.sleep(10000);
    }
}

给我输出 -

A
In the sleep function

而不是预期的

A
B
In the sleep function

有任何想法吗?

4

2 回答 2

0

您可能需要将测试作为 JUnit 插件测试运行。你试过吗?

于 2012-04-08T20:36:50.280 回答
0

所以事实证明答案是这样的(stackoverflow的一个很好的优点是我实际上在其他地方解决了这个问题,记得我遇到过类似的问题,然后不得不回到stackoverflow来提醒自己细节)

SWTBot 没有在 UI 线程中正确运行,因此出现空指针错误,我必须做的是有效地使用:

Display display = bot.getDisplay();
display.syncExec(objectThatdoesthethingiwanttogetdoneintheUIthread);
System.out.println(objectThatdoesthethingiwanttogetdoneintheUIthread.results);

......这让事情变得正常......

于 2012-04-22T09:58:02.810 回答