简体   繁体   English

带有鼠标单击事件的Junit测试

[英]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. 我有一个包含JTabel和JTextField的Jpanel,当单击该行两次时,将显示Jtable行的值。 the user can edit the JTextField value than click a button to update once the button is click the updateUser method will be called. 用户可以编辑JTextField值,而不是单击按钮来更新JTextField值,只要单击该按钮,就会调用updateUser方法。 I am trying to write a JUnit test to test that the updateUser is updating user. 我试图编写一个JUnit测试来测试updateUser正在更新用户。 How can I perform double click on a specific table row to get the data displayed in the specified JTextField? 如何双击特定表行以使数据显示在指定的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: Unittest应该测试单元,特别是逻辑单元,在您的情况下,我会将updateUser()方法更改为:

bool updateUser(String id, String name)

which you can test then undependant from the GUI elements. 然后您可以测试它,而与GUI元素无关。 The showConfirmDialog can then be shown according to the return value of the updateUser method. 然后可以根据updateUser方法的返回值显示showConfirmDialog

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

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