2012-04-07 98 views
0

所以我正在用SWTbot测试一个eclipse插件,我没有得到我期望的结果 - 当我减少测试结果时,事实证明问题不在于bot它与一些代码,我从该计划的另一部分(它是全功能)复制翻过SWTbot测试不像预期的那样

下面的代码...

@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 

任何想法?

回答

0

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

了SWTBot没有在UI线程中运行,因此正确的空指针错误,我要做的就是使用有效:

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

...那得到的东西的工作...

0

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

+0

我正在运行它作为SWTBot测试...我不相信SWTB ot funcationality工程,否则...可能是错误的,但... – Joe 2012-04-08 21:03:54

+0

你可以请检查activeWorkbenchWindow是否为空? – 2012-04-08 21:17:07

相关问题