-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for JUnit 5 #259
Comments
Hi @LorenzoBettini , You can define a import org.assertj.swing.junit.runner.FailureScreenshotTaker;
import org.assertj.swing.junit.runner.ImageFolderCreator;
import org.junit.jupiter.api.extension.Extension;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.InvocationInterceptor;
import org.junit.jupiter.api.extension.ReflectiveInvocationContext;
import java.lang.reflect.Method;
import static org.assertj.swing.annotation.GUITestFinder.isGUITest;
import static org.assertj.swing.junit.runner.Formatter.testNameFrom;
/**
* Understands a JUnit 5 extension that takes a screenshot of a failed GUI test.
* The Junit 4 runner is available in {@link org.assertj.swing.junit.runner.GUITestRunner}.
*
* @see <a href="https://github.com/assertj/assertj-swing/issues/259">assertj-swing #259</a>
* @author William Bakker
*/
public class GUITestExtension implements Extension, InvocationInterceptor {
private final FailureScreenshotTaker screenshotTaker;
public GUITestExtension() {
screenshotTaker = new FailureScreenshotTaker(new ImageFolderCreator().createImageFolder());
}
@Override
public void interceptTestMethod(
Invocation<Void> invocation,
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext)
throws Throwable {
try {
invocation.proceed();
} catch (Throwable t) {
takeScreenshot(invocationContext.getExecutable());
throw t;
}
}
private void takeScreenshot(Method method) {
final Class<?> testClass = method.getDeclaringClass();
if (!(isGUITest(testClass, method)))
return;
screenshotTaker.saveScreenshot(testNameFrom(testClass, method));
}
} |
Ah, that is interesting. We had made our own JUnit 5 extension for AssertJ-Swing but we didn't even think of putting in a screenshot taker, all ours does is spin up the Robot and tear it down at the end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi
is there any plan to provide something similar to the
GUITestRunner
andAssertJSwingJUnitTestCase
for JUnit 5? I guess that the corresponding mechanism ofGUITestRunner
would be a Jupiter extension?The text was updated successfully, but these errors were encountered: