So i am making a school project with javaFX and i need to make test with junit 5. But when i try to run my test i get an ExceptionInitializeError because the “ToolKit” is not initialized. How can i initialize this toolkit?
public class RegisterTest {
private Register register;
private User user;
@BeforeEach
public void setUp() {
register = new Register();
register.username = new TextField();
register.email = new TextField();
register.password = new TextField();
register.confirmPassword = new TextField();
user = mock(User.class);
}
@Test
public void testValidUser() {
when(user.checkNewUsername(anyString())).thenReturn(true);
when(user.checkNewEmail(anyString())).thenReturn(true);
when(user.checkNewPassword(anyString())).thenReturn(true);
assertTrue(register.validUser());
}
i asked chatgtp and i gave me an initializor that runs @Beforeall.
@BeforeAll
public static void initToolkit() {
new JFXPanel(); // Initializes the JavaFX toolkit
}
New contributor
DianH is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.