Skip to content

Conversation

wjbakker
Copy link

@wjbakker wjbakker commented Jan 8, 2022

Adds a Junit-Jupiter Extension for tests annotated with @GUITest.

Tests can now be run with the @GUITestExtension.

A new module is added:

<dependency>
  <groupId>org.assertj</groupId>
  <artifactId>assertj-swing-junit-jupiter</artifactId>
</dependency>

Example usage:

@ExtendWith(GUITestExtension.class)
class MyGuiTest {
  (...)
}

Solves !259

Adds a Junit-Jupiter Extension for tests annotated with @GUITest.
@gschrader
Copy link
Contributor

gschrader commented Apr 12, 2022

I'm not sure if you're still using AssertJSwingTestCaseTemplate for your tests but I found that tests would hang if you had an exception in any @BeforeEach or @AfterEach. I worked around that (I think) using this extension:

@RegisterExtension
InvocationInterceptor invocationInterceptor = new InvocationInterceptor() {
    @Override
    public void interceptBeforeEachMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable {
        proceedWithRobotCleanup(invocation);
    }


  @Override
    public void interceptAfterEachMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable {
        proceedWithRobotCleanup(invocation);
    }


    private void proceedWithRobotCleanup(Invocation<Void> invocation) throws Throwable {
        try {
            invocation.proceed();
        } catch (Throwable e) {
            if (robot() != null) {
                cleanUp();
            }
            throw e;
        }
    }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants