在junit4中的监听接口为RunnerListener,具体的实现为:
package org.junit.runner.notification; import org.junit.runner.Description; import org.junit.runner.Result; public class RunListener { public void testRunStarted(Description description) throws Exception { } public void testRunFinished(Result result) throws Exception { } public void testStarted(Description description) throws Exception { } public void testFinished(Description description) throws Exception { } public void testFailure(Failure failure) throws Exception { } public void testAssumptionFailure(Failure failure) { } public void testIgnored(Description description) throws Exception { } }
通知的类为:
package org.junit.runner.notification; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import org.junit.runner.Description; import org.junit.runner.Result; public class RunNotifier { private final List<RunListener> fListeners; private boolean fPleaseStop; public RunNotifier() { this.fListeners = Collections.synchronizedList(new ArrayList()); this.fPleaseStop = false; } public void addListener(RunListener listener) { this.fListeners.add(listener); } public void removeListener(RunListener listener) { this.fListeners.remove(listener); } public void fireTestRunStarted(Description description) { new SafeNotifier(description) { protected void notifyListener(RunListener each) throws Exception { each.testRunStarted(this.val$description); } }.run(); } public void fireTestRunFinished(Result result) { new SafeNotifier(result) { protected void notifyListener(RunListener each) throws Exception { each.testRunFinished(this.val$result); } }.run(); } public void fireTestStarted(Description description) throws StoppedByUserException { if (this.fPleaseStop) throw new StoppedByUserException(); new SafeNotifier(description) { protected void notifyListener(RunListener each) throws Exception { each.testStarted(this.val$description); } }.run(); } public void fireTestFailure(Failure failure) { new SafeNotifier(failure) { protected void notifyListener(RunListener each) throws Exception { each.testFailure(this.val$failure); } }.run(); } public void fireTestAssumptionFailed(Failure failure) { new SafeNotifier(failure) { protected void notifyListener(RunListener each) throws Exception { each.testAssumptionFailure(this.val$failure); } }.run(); } public void fireTestIgnored(Description description) { new SafeNotifier(description) { protected void notifyListener(RunListener each) throws Exception { each.testIgnored(this.val$description); } }.run(); } public void fireTestFinished(Description description) { new SafeNotifier(description) { protected void notifyListener(RunListener each) throws Exception { each.testFinished(this.val$description); } }.run(); } public void pleaseStop() { this.fPleaseStop = true; } public void addFirstListener(RunListener listener) { this.fListeners.add(0, listener); } private abstract class SafeNotifier { void run() { Iterator all; synchronized (RunNotifier.this.fListeners) { for (all = RunNotifier.this.fListeners.iterator(); all .hasNext();) try { notifyListener((RunListener) all.next()); } catch (Exception e) { all.remove(); RunNotifier.this.fireTestFailure(new Failure( Description.TEST_MECHANISM, e)); } } } protected abstract void notifyListener(RunListener paramRunListener) throws Exception; }
SWTBot的截屏通知为:
package org.eclipse.swtbot.swt.finder.junit; import org.apache.log4j.Logger; import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; import org.eclipse.swtbot.swt.finder.utils.SWTUtils; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunListener; /** * Captures screenshots on failure notifications. * * @author Hans Schwaebli (Bug 259787) * @version $Id$ * @noinstantiate This class is not intended to be instantiated by clients. */ public final class ScreenshotCaptureListener extends RunListener { /** The logger. */ private static Logger log = Logger.getLogger(SWTBotApplicationLauncherClassRunner.class); /** Counts the screenshots to determine if maximum number is reached. */ private static int screenshotCounter = 0; public void testFailure(Failure failure) throws Exception { captureScreenshot(failure); } private void captureScreenshot(Failure failure) { try { int maximumScreenshots = SWTBotPreferences.MAX_ERROR_SCREENSHOT_COUNT; String fileName = SWTBotPreferences.SCREENSHOTS_DIR + "/" + failure.getTestHeader() + "." + SWTBotPreferences.SCREENSHOT_FORMAT.toLowerCase(); //$NON-NLS-1$ if (++screenshotCounter <= maximumScreenshots) { captureScreenshot(fileName); } else { log.info("No screenshot captured for '" + failure.getTestHeader() + "' because maximum number of screenshots reached: " //$NON-NLS-1$ + maximumScreenshots); } } catch (Exception e) { log.warn("Could not capture screenshot", e); //$NON-NLS-1$ } } private boolean captureScreenshot(String fileName) { return SWTUtils.captureScreenshot(fileName); } public int hashCode() { return 31; } public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; return true; } }
相关推荐
SWTBot收集
swtbot简介、体系结构、如何安装、示例详解、架构、自定义部件等
swtbot学习资料,是swtbot官方的资料入门手册
在Java世界,GUI测试从来都是一个痛,SWTBOT从某种程度上可以帮助自动化GUI的测试,当然了,是否适用于你的项目还需要看具体情况分析。这篇文章对如果使用SWTBOT自动测试GUI有比较深入浅出的介绍
SWTBot自动化测试学习软件
swtbotw例子,swtbotw例子,swtbotw例子
swtbot运行原理
swtbot eclipse插件 测试界面
SWTBot对Eclipse的SWT UI画面测自动化测试及例子
背景简介 SWTBot是一个基于Java的新兴开源项目,致力于实现对基于SWT和Eclipse的应用程序GUI的自动化测试。当前,基于eclipse和SWT的产品非常多,随之而来的对于这一类产品的自动化测试需求也就越来越多。SWTBot...
方案示例-swtbot-e4 结合使用场景和SWTBot来测试和记录Eclipse RCP e4示例应用程序的示例UI测试和Scenarioo集成可在plugins/org.scenarioo.example.e4.test/src/org/scenarioo/example/e4文件夹中找到。构建并运行...
在Eclipse环境下建立swtbot的Web应用测试环境,并对具体的Web应用进行测试,详细描述测试过程. ... ---------------- 非原创,来源于互联网
SWTBot是用于SWT / RCP应用程序的自动化和测试工具,具有记录和回放脚本的功能。 功能将包括基于文本的脚本,对测试套件的回放,报告和多线程回放的ant支持。
NULL 博文链接:https://mwhgjava.iteye.com/blog/2257771
How to create plug-ins for Eclipse 3.x and 4.x and automatically test plug-ins with JUnit How to display tree and table information in views What are the specific differences between the Eclipse 3....
pdi-ui-test 基于SWTBot的用于Pentaho数据集成的UI测试的集合
Codenvy 的 Eclipse 插件描述该项目旨在提供一个 Eclipse 插件,使开发人员能够在 Codenvy 或 Eclipse 中工作,共享相同的代码库,而无需 Git 存储库。更新站点每晚构建: : 主要更新站点: : 使用 Maven 构建项目...
基于SWT和eclipse的开发越来越多,于是GUI的测试也越发显得重要,SWVBOT工具就是为了方便GUI的测试而出的新一个测试工具。。。 提供资源共大家学习