标签:
1 import java.awt.BorderLayout; 2 import java.awt.Container; 3 import java.awt.event.ActionEvent; 4 import java.awt.event.ActionListener; 5 6 import javax.swing.Box; 7 import javax.swing.BoxLayout; 8 import javax.swing.JButton; 9 import javax.swing.JFrame; 10 import javax.swing.JLabel; 11 import javax.swing.JTextField; 12 13 public class MyFrame extends JFrame { 14 public MyFrame() { 15 setTitle("My Frame"); 16 setSize(200, 100); 17 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 18 19 Container content = getContentPane(); 20 Box vbox = new Box(BoxLayout.Y_AXIS); 21 content.add(vbox, BorderLayout.CENTER); 22 23 final JLabel showTextLabel = new JLabel(" "); 24 showTextLabel.setName("show"); 25 vbox.add(showTextLabel); 26 final JTextField input = new JTextField(); 27 input.setName("input"); 28 vbox.add(input); 29 JButton button = new JButton("copy"); 30 button.setName("copy"); 31 button.addActionListener(new ActionListener() { 32 33 @Override 34 public void actionPerformed(ActionEvent e) { 35 showTextLabel.setText(input.getText()); 36 } 37 38 }); 39 vbox.add(button); 40 } 41 }
1 private FrameFixture frame; 2 3 @Before 4 public void setUp() { 5 frame = new FrameFixture(new MyFrame()); 6 frame.show(); // 将frame显示出来 7 } 8 9 //在@After方法中对其进行清理: 10 @After 11 public void tearDown() { 12 frame.cleanUp(); 13 } 14 15 //然后编写@Test方法: 16 @Test 17 public void testCopyTextToLabel() { 18 frame.textBox("input").enterText("Hello World!"); 19 frame.button("copy").click(); 20 frame.label("show").requireText("Hello World!"); 21 }
1 import org.fest.swing.fixture.FrameFixture; 2 import org.junit.After; 3 import org.junit.Before; 4 import org.junit.Test; 5 6 public class MyFrameTest { 7 8 private FrameFixture frame; 9 10 @Before 11 public void setUp() { 12 frame = new FrameFixture(new MyFrame()); 13 frame.show(); 14 } 15 16 @After 17 public void tearDown() { 18 frame.cleanUp(); 19 } 20 21 @Test 22 public void testCopyTextToLabel() { 23 frame.textBox("input").enterText("Hello World!"); 24 frame.button("copy").click(); 25 frame.label("show").requireText("Hello World!"); 26 } 27 }
本文出自 “豆子空间” 博客,请务必保留此出处http://devbean.blog.51cto.com/448512/126828
标签:
原文地址:http://www.cnblogs.com/bbker/p/4504814.html