Hof*_*ann 0 java junit swing unit-testing
我需要在JDialog中激活JButton ActionListener,这样我就可以使用JUnit进行一些单元测试了.
基本上我有这个:
public class MyDialog extends JDialog {
public static int APPLY_OPTION= 1;
protected int buttonpressed;
protected JButton okButton;
public MyDialog(Frame f) {
super(f);
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonpressed= APPLY_OPTION;
}
} );
public int getButtonPressed() {
return buttonpressed;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我有我的JUnit文件:
public class testMyDialog {
@Test
public void testGetButtonPressed() {
MyDialog fc= new MyDialog(null);
fc.okButton.???????? //how do I activate the ActionListener?
assertEquals(MyDialog.APPLY_OPTION, fc.getButtonPressed());
}
}
Run Code Online (Sandbox Code Playgroud)
在单元测试中这可能听起来多余,但实际的类比那复杂得多......
| 归档时间: |
|
| 查看次数: |
11164 次 |
| 最近记录: |