Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > de.comp.lang.java > #12987
| From | "Christian H. Kuhn" <qno-news@qno.de> |
|---|---|
| Newsgroups | de.comp.lang.java |
| Subject | JUnit Test von JButton: Action wird nicht erkannt |
| Date | 2016-07-14 01:09 +0200 |
| Message-ID | <duo028Fb4qaU1@mid.individual.net> (permalink) |
Hallo Gemeinde,
Ich verzweifle gerade.
Vollständiger Code auf https://www.qno.de/gitweb/, Branch v0.8.4. Die
wichtigsten Ausschnitte:
public class QChessClockJavaAV extends JFrame implements
QChessClockObserver, ActionListener {
(...)
private final transient JButton resetButton;
(...)
public QChessClockJavaAV(final QChessClock _clock) {
super("QChessClock – The JAVA Chess Clock from your FIDE Arbiter");
final JPanel contentPanel = new JPanel();
contentPanel.setLayout(new GridBagLayout());
final GridBagConstraints constraint = new GridBagConstraints();
constraint.fill = GridBagConstraints.BOTH;
constraint.weightx = 1;
(...)
resetButton = new JButton("R");
resetButton.setActionCommand("reset");
resetButton.addActionListener(this);
resetButton.setMinimumSize(QChessClockJavaAV.BUTTON_DIMENSION);
resetButton.setName("ResetButton");
constraint.gridx = 1;
constraint.gridy = 1;
contentPanel.add(resetButton, constraint);
}
(...)
public final void actionPerformed(final ActionEvent _event) {
final String myActionCommand = _event.getActionCommand();
switch (myActionCommand) {
case "reset":
clock.resetPressed();
break;
(...)
default:
}
}
(...)
}
public class QChessClockJavaAVTest implements QChessClockObserver {
private transient QChessClockJavaAV sut;
private transient QChessClock clock;
private transient JButton resetButton;
private transient QChessClockState status;
@Before
public final void setUp() throws Exception {
clock = new QChessClock();
clock.addObserver(this);
sut = new QChessClockJavaAV(clock);
resetButton = (JButton) TestUtils.getChildNamed(sut, "ResetButton");
}
public final void update(final QChessClockState _state) {
status = _state;
}
@Test
public final void pressResetButtonTest() throws Throwable {
leftButton.doClick();
stopButton.doClick();
Thread.sleep(TWO_CYCLES);
resetButton.doClick();
Thread.sleep(TWO_CYCLES);
assertSame(QChessClockState.NOT_STARTED, status);
}
}
TestUtils von
http://www.javaworld.com/article/2073056/swing-gui-programming/automate-gui-tests-for-swing-applications.html
Der Test fails. status ist STOPPED, was es nach stopButton.doClick sein
sollte, aber nicht mehr nach resetButton.doClick.
resetButton wurde korrekt aufgefunden, wie durch einen Test mit
setBackground(Color) herausgefunden wurde.
Wird QChessClockJavaAV normal gestartet und mit der Maus bedient,
funktioniert der Button wie geplant.
Alle anderen Knöpfe reagieren wie gewollt auf doClick().
resetButton.doClick() löst keine Aktion aus, oder zumindest wird sie
nicht von actionPerformed() in QChessClockJavaAV aufgefangen. Ein
Breakpoint zu Beginn von actionPerformed() hält im Debugger bei allen
anderen Knöpfen an, wird aber bei resetButton.onClick() nicht getroffen.
Stattdessen wird die nächste Zeile im Test, Thread.sleep(), ausgeführt.
Ich habe auch versucht, den Knopf mit doClick(1000) länger zu drücken.
Gleicher Fehler.
Mir fehlen die Ideen, wo ich noch suchen soll. Alle mir vorstellbaren
Fehlermöglichkeiten sind ausgeschlossen. Und am Ende ist es dann wie
üblich irgendwas ganz primitives ...
TIA
QNo
Back to de.comp.lang.java | Previous | Next — Next in thread | Find similar
JUnit Test von JButton: Action wird nicht erkannt "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-14 01:09 +0200
Re: JUnit Test von JButton: Action wird nicht erkannt "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-14 18:26 +0200
Re: JUnit Test von JButton: Action wird nicht erkannt Patrick Roemer <sangamon@netcologne.de> - 2016-07-14 19:47 +0200
Re: JUnit Test von JButton: Action wird nicht erkannt "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-15 00:08 +0200
Re: JUnit Test von JButton: Action wird nicht erkannt Patrick Roemer <sangamon@netcologne.de> - 2016-07-15 22:04 +0200
Re: JUnit Test von JButton: Action wird nicht erkannt "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-15 22:53 +0200
Re: JUnit Test von JButton: Action wird nicht erkannt "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-15 23:09 +0200
Re: JUnit Test von JButton: Action wird nicht erkannt Patrick Roemer <sangamon@netcologne.de> - 2016-07-15 23:44 +0200
Countdown Timer Design (was: JUnit Test von JButton: Action wird nicht erkannt) "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-16 23:44 +0200
Re: Countdown Timer Design "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-17 12:44 +0200
Re: Countdown Timer Design "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-17 15:49 +0200
Re: Countdown Timer Design "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-17 17:03 +0200
Re: Countdown Timer Design "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-19 15:59 +0200
Re: JUnit Test von JButton: Action wird nicht erkannt "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-19 14:59 +0200
Re: JUnit Test von JButton: Action wird nicht erkannt "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-19 16:06 +0200
Re: JUnit Test von JButton: Action wird nicht erkannt Patrick Roemer <sangamon@netcologne.de> - 2016-07-19 18:59 +0200
Re: JUnit Test von JButton: Action wird nicht erkannt "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-19 22:35 +0200
Re: JUnit Test von JButton: Action wird nicht erkannt Patrick Roemer <sangamon@netcologne.de> - 2016-07-20 13:00 +0200
Re: JUnit Test von JButton: Action wird nicht erkannt "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-23 20:36 +0200
Re: JUnit Test von JButton: Action wird nicht erkannt "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-23 23:15 +0200
Re: JUnit Test von JButton: Action wird nicht erkannt Wanja Gayk <brixomatic@yahoo.com> - 2016-07-19 23:02 +0200
Re: JUnit Test von JButton: Action wird nicht erkannt "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-20 12:33 +0200
GUI-Update über Swing-EDT (was: JUnit Test von JButton: Action wird nicht erkannt) "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-15 12:03 +0200
Re: GUI-Update über Swing-EDT Patrick Roemer <sangamon@netcologne.de> - 2016-07-15 22:43 +0200
Re: GUI-Update über Swing-EDT "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-15 23:18 +0200
Re: GUI-Update über Swing-EDT "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-16 15:24 +0200
Re: GUI-Update über Swing-EDT Patrick Roemer <sangamon@netcologne.de> - 2016-07-16 16:42 +0200
Re: GUI-Update über Swing-EDT "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-16 23:05 +0200
Re: GUI-Update über Swing-EDT "Christian H. Kuhn" <qno-news@qno.de> - 2016-07-17 16:02 +0200
csiph-web