如何模拟在摆动弹出对话框中单击按钮? [英] How do simulate a button click in a swing pop up dialog?
本文介绍了如何模拟在摆动弹出对话框中单击按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Java新手,我想为名称验证类编写一个JUnit测试
I'm new to Java, I want to write a JUnit test for a name validate class
我要测试以下代码:
public boolean createNewUMLClassFromString(String className) {
if(validate(className)){
....
}
return false;
}
private boolean validate(String userInput){
/* check if it's empty */
if (userInput.equals("")){
JOptionPane.showMessageDialog(null, "Class Name can't be empty");
return false;
}
return true;
}
所以我写了一个JUnit
So I wrote a JUnit
public void emptyStringCheckerTest(){
assertFalse("new class can not be empty", um.createNewUMLClassFromString("do"));
}
它可以工作,但是在测试运行过程中,我每次都需要单击弹出对话框.
it works, but in the test running process, I need to click the pop up dialog every time.
那么有人可以告诉我如何在测试过程中模拟按钮单击吗?还是有更好的方法编写测试?谢谢吗?
So Is anyone can tell me how to simulate a button click in the test process, or Is there a better way to write the test? Thanks?
推荐答案
Look at java.awt.Robot
, and at libraries like abbot
http://abbot.sourceforge.net/doc/overview.shtml that enhance it.
这篇关于如何模拟在摆动弹出对话框中单击按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文