繁体   English   中英

AssertJ Swing 的设置 - 测试 GUI

[英]Setup for AssertJ Swing - testing GUI

我正在尝试测试银行系统应用程序的 GUI,但在 TestLogin 类中出现错误“无法解析构造函数 FrameFixture(GUI.Login)”。 我尝试在 Login 类中扩展 SampleFrame 类,但是 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();
    }
}

这是登录类:

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();
    }
}

并在 Login 类中添加

public class Login extends JFrame

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM