AssertJ Swing 的设置 - 测试 GUI
Setup for AssertJ Swing - testing GUI
我正在尝试测试银行系统应用程序的 GUI,但在 TestLogin class 中出现错误“无法解析构造函数 'FrameFixture(GUI.Login)'”。我试图在登录 class 中扩展 SampleFrame class,但 IntelliJ 找不到依赖项。我该怎么做才能解决这个问题?
public class TestLogin {
protected FrameFixture window;
@BeforeClass
public static void setUpOnce() {
FailOnThreadViolationRepaintManager.install();
}
@Before
public void setUp() {
Login frame = GuiActionRunner.execute(() -> new Login());
window = new FrameFixture(frame); //Cannot resolve constructor 'FrameFixture(GUI.Login)
window.show();
}
@Test
public void test() {}
@After
public void tearDown() {
window.cleanUp();
}
}
这是登录名 class:
package GUI;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Login{
public JFrame frame;
private JTextField textField;
private JPasswordField textField_1;
/**
* Create the application.
*/
public Login() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Banking System");
frame.getContentPane().setLayout(null);
JLabel label = new JLabel("Banking System");
label.setFont(new Font("Tahoma", Font.BOLD, 17));
label.setBounds(147, 11, 151, 41);
frame.getContentPane().add(label);
JLabel lblLoginScreen = new JLabel("Login Screen");
lblLoginScreen.setFont(new Font("Tahoma", Font.PLAIN, 13));
lblLoginScreen.setBounds(170, 63, 101, 23);
frame.getContentPane().add(lblLoginScreen);
JLabel lblUsername = new JLabel("Username:");
lblUsername.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblUsername.setBounds(55, 119, 64, 23);
frame.getContentPane().add(lblUsername);
JLabel lblPassword = new JLabel("Password:");
lblPassword.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblPassword.setBounds(55, 159, 64, 23);
frame.getContentPane().add(lblPassword);
textField = new JTextField();
textField.setBounds(130, 121, 86, 20);
frame.getContentPane().add(textField);
textField.setColumns(10);
textField.setText("admin");
textField_1 = new JPasswordField();
textField_1.setBounds(130, 161, 86, 20);
frame.getContentPane().add(textField_1);
textField_1.setColumns(10);
JButton btnLogin = new JButton("Login");
btnLogin.addActionListener(new ActionListener() {
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent e) {
String user,pass;
textField.setText("admin");
user="admin";
pass=textField_1.getText();
if((user.equals("admin")&&(pass.equals("admin"))))
{
JOptionPane.showMessageDialog(frame.getComponent(0), "Login Successfully");
frame.setVisible(false);
GUIForm.menu.setVisible(true);
}
else
{
JOptionPane.showMessageDialog(frame.getComponent(0), "Login Failed");
}
}
});
btnLogin.setBounds(260, 138, 89, 23);
frame.getContentPane().add(btnLogin);
}
}
尝试
public class TestLogin extends AssertJSwingJUnitTestCase {
private FrameFixture window;
@Override
protected void onSetUp() {
Login frame = GuiActionRunner.execute(() -> new Login());
window = new FrameFixture(robot(), frame);
window.show();
}
@Test
public void test(){
}
@Override
protected void onTearDown () {
window.cleanUp();
}
}
并在登录 class 添加
public class Login extends JFrame
我正在尝试测试银行系统应用程序的 GUI,但在 TestLogin class 中出现错误“无法解析构造函数 'FrameFixture(GUI.Login)'”。我试图在登录 class 中扩展 SampleFrame class,但 IntelliJ 找不到依赖项。我该怎么做才能解决这个问题?
public class TestLogin {
protected FrameFixture window;
@BeforeClass
public static void setUpOnce() {
FailOnThreadViolationRepaintManager.install();
}
@Before
public void setUp() {
Login frame = GuiActionRunner.execute(() -> new Login());
window = new FrameFixture(frame); //Cannot resolve constructor 'FrameFixture(GUI.Login)
window.show();
}
@Test
public void test() {}
@After
public void tearDown() {
window.cleanUp();
}
}
这是登录名 class:
package GUI;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Login{
public JFrame frame;
private JTextField textField;
private JPasswordField textField_1;
/**
* Create the application.
*/
public Login() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Banking System");
frame.getContentPane().setLayout(null);
JLabel label = new JLabel("Banking System");
label.setFont(new Font("Tahoma", Font.BOLD, 17));
label.setBounds(147, 11, 151, 41);
frame.getContentPane().add(label);
JLabel lblLoginScreen = new JLabel("Login Screen");
lblLoginScreen.setFont(new Font("Tahoma", Font.PLAIN, 13));
lblLoginScreen.setBounds(170, 63, 101, 23);
frame.getContentPane().add(lblLoginScreen);
JLabel lblUsername = new JLabel("Username:");
lblUsername.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblUsername.setBounds(55, 119, 64, 23);
frame.getContentPane().add(lblUsername);
JLabel lblPassword = new JLabel("Password:");
lblPassword.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblPassword.setBounds(55, 159, 64, 23);
frame.getContentPane().add(lblPassword);
textField = new JTextField();
textField.setBounds(130, 121, 86, 20);
frame.getContentPane().add(textField);
textField.setColumns(10);
textField.setText("admin");
textField_1 = new JPasswordField();
textField_1.setBounds(130, 161, 86, 20);
frame.getContentPane().add(textField_1);
textField_1.setColumns(10);
JButton btnLogin = new JButton("Login");
btnLogin.addActionListener(new ActionListener() {
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent e) {
String user,pass;
textField.setText("admin");
user="admin";
pass=textField_1.getText();
if((user.equals("admin")&&(pass.equals("admin"))))
{
JOptionPane.showMessageDialog(frame.getComponent(0), "Login Successfully");
frame.setVisible(false);
GUIForm.menu.setVisible(true);
}
else
{
JOptionPane.showMessageDialog(frame.getComponent(0), "Login Failed");
}
}
});
btnLogin.setBounds(260, 138, 89, 23);
frame.getContentPane().add(btnLogin);
}
}
尝试
public class TestLogin extends AssertJSwingJUnitTestCase {
private FrameFixture window;
@Override
protected void onSetUp() {
Login frame = GuiActionRunner.execute(() -> new Login());
window = new FrameFixture(robot(), frame);
window.show();
}
@Test
public void test(){
}
@Override
protected void onTearDown () {
window.cleanUp();
}
}
并在登录 class 添加
public class Login extends JFrame