JUnit JavaFX 工具包未初始化
J-Unit JavaFX Tookit not Initialized
我为我在 JavaFX 项目中使用的 class 编写了一些 J 单元测试。然而,我一次又一次地 运行 进入 "Tookit not initialized"。我是 JavaFX 和 J-Unit 测试的新手,所以我不确定去哪里找。
我将 VM 选项从 -ea 编辑为“--module-path C:\Users\myName\Desktop\javafx-sdk-14.0.1\lib --add-modules javafx.controls,javafx.fxml" 以修复未找到合适的管道错误。
这是我的测试class代码:
package HHS_PROJ1.models;
import javafx.scene.control.Button;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.*;
class AnimalTest {
private Animal animal;
@BeforeEach
void setUp() {
animal = new Animal(5, "Goat", 32, 10, 0, new Button("bid"));
}
@Test
void setHighestOffer() {
try {
animal.setHighestOffer(8);
fail("Entering a lower offer than current highestOffer should throw an exception");
} catch (IllegalArgumentException e) {
System.out.println("Caught lower offer than current highest in setHighestOffer(): " + e.getMessage());
} catch (Exception e) {
fail("Wrong exception thrown for entering a lower offer than the current highestOffer");
}
}
@Test
void setAmount() {
try {
animal.setAmount(-2);
fail("Entering a negative number should throw an exception");
} catch (IllegalArgumentException e) {
System.out.println("Caught negative number in setAmount(): " + e.getMessage());
} catch (Exception e) {
fail("Wrong exception thrown for entering a negative number");
}
}
}
我希望能够 运行 我的测试,看看我的代码是否按预期工作。
我通过创建私有 JFXPanel 解决了这个问题,然后将以下位添加到 VM 选项 "javafx.web,javafx.media,javafx.swing"
我为我在 JavaFX 项目中使用的 class 编写了一些 J 单元测试。然而,我一次又一次地 运行 进入 "Tookit not initialized"。我是 JavaFX 和 J-Unit 测试的新手,所以我不确定去哪里找。
我将 VM 选项从 -ea 编辑为“--module-path C:\Users\myName\Desktop\javafx-sdk-14.0.1\lib --add-modules javafx.controls,javafx.fxml" 以修复未找到合适的管道错误。
这是我的测试class代码:
package HHS_PROJ1.models;
import javafx.scene.control.Button;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.*;
class AnimalTest {
private Animal animal;
@BeforeEach
void setUp() {
animal = new Animal(5, "Goat", 32, 10, 0, new Button("bid"));
}
@Test
void setHighestOffer() {
try {
animal.setHighestOffer(8);
fail("Entering a lower offer than current highestOffer should throw an exception");
} catch (IllegalArgumentException e) {
System.out.println("Caught lower offer than current highest in setHighestOffer(): " + e.getMessage());
} catch (Exception e) {
fail("Wrong exception thrown for entering a lower offer than the current highestOffer");
}
}
@Test
void setAmount() {
try {
animal.setAmount(-2);
fail("Entering a negative number should throw an exception");
} catch (IllegalArgumentException e) {
System.out.println("Caught negative number in setAmount(): " + e.getMessage());
} catch (Exception e) {
fail("Wrong exception thrown for entering a negative number");
}
}
}
我希望能够 运行 我的测试,看看我的代码是否按预期工作。
我通过创建私有 JFXPanel 解决了这个问题,然后将以下位添加到 VM 选项 "javafx.web,javafx.media,javafx.swing"