assertj / assertj/assertj-swing
JMockit Mocks Are Not Being Created
- Vorherrschende Sprache
- Java
- Sterne
- 121
- Forks
- 52
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
I took the code example from here https://stackoverflow.com/questions/14375854/jmockit-and-fest-ui-testing and put it in a gradle project here https://github.com/opticyclic/assertj-swing-mocks
The [test](https://github.com/opticyclic/assertj-swing-mocks/blob/master/src/test/java/com/github/opticyclic/demo/assertj/SimpleFormTest.java) code inside the `GuiActionRunner` doesn't seem to get mocked even though the code outside it does.
```
@Override
protected void onSetUp() {
//Mock the Service
new Expectations() {{
service.getValue();
result = mockText;
}};
//Demonstrate that the mocking is working here
SimpleService simpleService = new SimpleService();
Assert.assertEquals(simpleService.getValue(), mockText);
JFrame frame = GuiActionRunner.execute(new GuiQuery() {
@Override
protected JFrame executeInEDT() {
SimpleController controller = new SimpleController();
JFrame frame = new JFrame("Simple Frame");
frame.add(controller.getPanel());
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.pack();
return frame;
}
});
```
The test fails with:
```
java.lang.AssertionError: [javax.swing.JButton[name='testButton', text='Not Mocked', enabled=true, visible=true, showing=true] - property:'text']
Expecting:
"Not Mocked"
to match pattern:
"Mock Button Text"
```
Why are the mocks not being created?
Beitragsleitfaden
Rechercherichtung
Beginne mit src/test/java/com/github/opticyclic/demo/assertj/SimpleFormTest.java und dem GuiActionRunner.execute-Aufruf im verlinkten Reproduktionsprojekt. Vergleiche das Mock-Verhalten außerhalb und innerhalb von executeInEDT, und führe den Test aus, um zu bestätigen, dass die Schaltfläche "Mock Button Text" statt "Not Mocked" erhält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- desktop, testing
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100