使用 RFT 和 AOP 相结合测试 SWT 应用程序

发表于:2008-6-06 10:31

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:宋政君 余晓峰    来源:51Testing软件测试论坛

3. 解决方案:直接修改 SWT 应用程序源代码

        为了使 RFT 能够捕捉到 SWT 程序的对象,您必须将清单 2 的代码添加到 SWT 应用程序的源代码中:


清单 2.
                
try {
      com.rational.test.ft.bootstrap.Bootstrap.enableSwtUi(display);
     }
catch (Throwable e){
     }

        其中:Bootstrap 类是 RFT 的运行时环境中 rational_ft_bootstrap.jar 文件包中的类。以上节的 SWT 程序为例,修改后的代码如下:


清单 3.
                
public class Calculator extends Composite {
	public Calculator(Composite parent, int style) {
		super(parent, style);
	}
private CalculatorModel model = new CalculatorModel();
	private Text lcd = new Text(this, SWT.BORDER | SWT.RIGHT);

//省略……

	public static void main(String[] args) {
		Display display = Display.getDefault();
		Shell shell = new Shell(display);
 try
 {
 Bootstrap.enableSwtUi(display);
 }
 catch(Throwable throwable) { }
		shell.setText("Calculator");
		shell.setLayout(new FillLayout());
		Calculator cal = new Calculator(shell, SWT.NONE);
		cal.init();
		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}
}

        并且为了能够编译和运行,您还必须把 rational_ft_bootstrap.jar 添加到 class path中,确保 SWT 应用程序运行时能够找到 Bootstrap 类。重新编译运行上面的例子,然后打开 RFT 的对象捕捉器,左键按住手形的对象选择器不放,将鼠标移到 SWT 应用程序的按钮对象上,如图 5 所示,SWT 对象被红框包围,并在下方显示出该对象的类型是:org.eclipse.swt.widgets.Button,说明 RFT 可以成功捕捉到 SWT 的对象了。


图 5. 捕捉 SWT 对象

图 5. 捕捉 SWT 对象

 
53/5<12345>
《2023软件测试行业现状调查报告》独家发布~

精彩评论

  • dreamever
    2008-6-06 12:03:44

    这个方法是很好,但是有一个问题:如果我们要这样做的话,是否意味着开发人员在写代码时,必须考虑和RFT的兼容性?

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号