简体   繁体   中英

Junit test with mouse click event

I have a Jpanel that contain a JTabel and JTextField that display the value of the Jtable row when the row is clicked twice. the user can edit the JTextField value than click a button to update once the button is click the updateUser method will be called. I am trying to write a JUnit test to test that the updateUser is updating user. How can I perform double click on a specific table row to get the data displayed in the specified JTextField?

 public void updateUser(){

      String  id= txtid.getText();
      String  name =txtName.getText();
      String q = "UPDATE `user` SET `name`=? WHERE `id`=?";
        try{
             PreparedStatement ps = Login.con.prepareStatement(q);
             ps.setString(2, id);
             ps.setString(1, name);
             ps.executeUpdate();
             JOptionPane.showConfirmDialog(null, "User Updated");
            }catch(Exception eu){

                      }
}

Unittest should test the Unit, specefically the logical unit, in your case i would change the updateUser() method to:

bool updateUser(String id, String name)

which you can test then undependant from the GUI elements. The showConfirmDialog can then be shown according to the return value of the updateUser method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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