使用FEST-Swing测试GUI

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField; public class MyFrame extends JFrame {
public MyFrame() {
setTitle("My Frame");
setSize(200, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = getContentPane();
Box vbox = new Box(BoxLayout.Y_AXIS);
content.add(vbox, BorderLayout.CENTER); final JLabel showTextLabel = new JLabel(" ");
showTextLabel.setName("show");
vbox.add(showTextLabel);
final JTextField input = new JTextField();
input.setName("input");
vbox.add(input);
JButton button = new JButton("copy");
button.setName("copy");
button.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
showTextLabel.setText(input.getText());
} });
vbox.add(button);
}
}
private FrameFixture frame; @Before
public void setUp() {
frame = new FrameFixture(new MyFrame());
frame.show(); // 将frame显示出来
} //在@After方法中对其进行清理:
@After
public void tearDown() {
frame.cleanUp();
} //然后编写@Test方法:
@Test
public void testCopyTextToLabel() {
frame.textBox("input").enterText("Hello World!");
frame.button("copy").click();
frame.label("show").requireText("Hello World!");
}
import org.fest.swing.fixture.FrameFixture;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; public class MyFrameTest { private FrameFixture frame; @Before
public void setUp() {
frame = new FrameFixture(new MyFrame());
frame.show();
} @After
public void tearDown() {
frame.cleanUp();
} @Test
public void testCopyTextToLabel() {
frame.textBox("input").enterText("Hello World!");
frame.button("copy").click();
frame.label("show").requireText("Hello World!");
}
}
本文出自 “豆子空间” 博客,请务必保留此出处http://devbean.blog.51cto.com/448512/126828
使用FEST-Swing测试GUI的更多相关文章
- AutoIT 测试GUI工具
今天听到同事提到AutoIT,可以用来测试GUI窗口.了解一下这个工具. 以下内容引自: http://www.jb51.net/article/14870.htm (此url非原出处,该博主未注明原 ...
- Swing的GUI组件得到焦点
Swing的GUI组件如JButtin,JTextArea,JRadioButton,JComboBox等,可以使用requestFocus()方法来获得焦点.
- 使用Swing的GUI编程
Swing AWT概述 AWT:抽象窗口工具包,提供了一套与本地图形界面进行交互的接口,是Java提供的用来建立和设置Java的图形用户界面的基本工具 Swing以AWT为基础的,尽管Swing消除了 ...
- NUnitForms 测试GUI应用程序的优秀工具
著名的NUnit是单元测试的优秀工具,但是要在一个测试方法中启动GUI程序,比如Windows Form界面,这比较难做到.NUnitForms就是为解决这个问题产生的,它是NUnit的一个扩展程序, ...
- 给Swing的GUI组件设置前景色和背景色
JButton btn=new JButton("TEST"); btn.setForeground(Color.white);// 设置前景色(文字颜色)btn.setBackg ...
- 转载:开发者眼中最好的 22 款 GUI 测试工具
对于很多同学来说gui程序的测试是一个难点,所以我从网上转载了一篇关于gui测试的一篇文章,里面罗列的很多工具,大家可以尝试一下学习学习. 英文原文:22 best GUI testing tools ...
- 开发者眼中最好的 22 款 GUI 测试工具
1.Abbot - Java GUI 测试框架 Abbot是一个基于GUI的简单的Java测试框架,它能够帮助开发者测试Java用户界面. 它提供事件自动生成和验证Java GUI组件,使您能够轻松地 ...
- Java进阶篇(六)——Swing程序设计(上)
Swing是GUI(图形用户界面)开发工具包,内容有很多,这里会分块编写,但在进阶篇中只编写Swing中的基本要素,包括容器.组件和布局等,更深入的内容会在高级篇中出现.想深入学习的朋友们可查阅有关资 ...
- Java客户端工具选择:HTML?Swing?XML?
整理下面的文章是因为个人觉得写的很好,关于java的客户端了解也并不是太多.看了下面的文章觉得很有必要贴出来,方便自己以后了解java客户端编程. Java软件设计师和管理人员经常会面临这样的难题:在 ...
随机推荐
- 由tombstone文件解析jni代码过程
Android开发测试会经常遇到crash. (1)adb shell (2)cd /data/tombstones/ (3)adb pull /data/tombstones/tombston_00 ...
- socket笔记
参考: http://www.cnblogs.com/dolphinX/p/3460545.html http://www.cnblogs.com/wei2yi/archive/2011/03/23/ ...
- 8.9 CSS知识点2
4.关系选择符 包含选择符(Descendant combinator) E F 选择所有被E元素包含的F元素 <style type="text/css"> h1 ...
- Jmeter之逻辑控制器(Logic Controller)
Jmeter之逻辑控制器(Logic Controller) 前言: 1. Jmeter官网对逻辑控制器的解释是:“Logic Controllers determine the order in w ...
- JSF 抽象和实现例子 (函数和属性)
ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/ ...
- Java NIO教程 Selector
这次我们开讲非阻塞I/O中的Selector,它需要配合非阻塞的TCP和UDP来使用.首先我们先简单讲一下TCP和UDP的非阻塞通道. 非阻塞I/O通道 在上代码前我们先讲解一些最基本的知识.TCP和 ...
- MCS-51系列特殊功能寄存器(摘抄)
1. P0 (80H) P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0 2.SP 栈指针(81H) 3.DPTR 数据指针(由DPH和DPL组成) DPL 数据指针低八 ...
- 爬虫---request+++urllib
网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本.另外一些不常使用的名字还有蚂蚁.自动索引.模拟程序或者蠕 ...
- js完美转换阿拉伯数字为数字大写(原创)
啥都不说,直接上代码: //阿拉伯数字转换为简写汉字 function Arabia_To_SimplifiedChinese(Num) { for (i = Num.length - 1; i &g ...
- PostGreSQL 分页
select * from users limit 10 offset 20; limit A offset B 其中A是页容量 B是偏移量 即跳过前20条 查询每页10条