3月 25, 2023 7:22:39 下午 org.fest.swing.monitor.ProtectingTimerTask handleException
警告: Exception thrown by a TimerTask
java.lang.reflect.InaccessibleObjectException: Unable to make field int java.util.TimerTask.state accessible: module java.base does not "opens java.util" to unnamed module @2077d4de
@Test
public void testValidCompany() {
/*
* 第一个测试用例,测试:航空公司名称的长度不能小于6
* 注意:其它输入项必须正确,否则,如何测试ValidCompany
*/
jfDlg.textBox("txtIDFest").setText("93687");
jfDlg.textBox("txtFnameFest").setText("YE4002");
jfDlg.textBox("txtCompanyFest").setText("sdfaa");
jfDlg.textBox("txtPriceFest").setText(" ");
jfDlg.textBox("txtSeatFest").setText("126");
jfDlg.button("btnOKFest").click();
try {
jfDlg.optionPane().okButton().click();
}catch (org.fest.swing.exception.WaitTimedOutError ignored){}
assertFalse(hif.GetValidFlight());
/*
* 第二个测试用例,测试:航空公司名称的长度不能大于20
* 注意:其它输入项必须正确,否则,如何测试ValidCompany
*/
jfDlg.textBox("txtIDFest").setText("93687");
jfDlg.textBox("txtFnameFest").setText("YE4002");
jfDlg.textBox("txtCompanyFest").setText("abcdeabcdeabcdeabcdea");
jfDlg.textBox("txtPriceFest").setText("1500.5");
jfDlg.textBox("txtSeatFest").setText("126");
jfDlg.button("btnOKFest").click();
try {
jfDlg.optionPane().okButton().click();
}catch (org.fest.swing.exception.WaitTimedOutError ignored){}
assertFalse(hif.GetValidFlight());
/*
* 第三个测试用例,测试:航空公司名称的首字母必须为‘H’
* 注意:其它输入项必须正确,否则,如何测试ValidCompany
*/
jfDlg.textBox("txtIDFest").setText("93687");
jfDlg.textBox("txtFnameFest").setText("YE4002");
jfDlg.textBox("txtCompanyFest").setText("hguohang");
jfDlg.textBox("txtPriceFest").setText("1500.5");
jfDlg.textBox("txtSeatFest").setText("126");
jfDlg.button("btnOKFest").click();
try {
jfDlg.optionPane().okButton().click();
}catch (org.fest.swing.exception.WaitTimedOutError ignored){}
assertFalse(hif.GetValidFlight());
/*
* 第四个测试用例,测试:航空公司名称的首字母必须为‘H’
* 注意:其它输入项必须正确,否则,如何测试ValidCompany
*/
jfDlg.textBox("txtIDFest").setText("93687");
jfDlg.textBox("txtFnameFest").setText("YE4002");
jfDlg.textBox("txtCompanyFest").setText("Hguohang");
jfDlg.textBox("txtPriceFest").setText("1500.5");
jfDlg.textBox("txtSeatFest").setText("126");
jfDlg.button("btnOKFest").click();
try {
jfDlg.optionPane().okButton().click();
}catch (org.fest.swing.exception.WaitTimedOutError ignored){}
assertTrue(hif.GetValidFlight());
}
求解决方案
把你项目中的module-info.java文件删掉
不知道你这个问题是否已经解决, 如果还没有解决的话:当我们希望测试耗时方法的执行时间,并不想让测试方法无限地等待时,就可以对测试方法进行超时测试,JUnit 5
对此推出了断言方法 assertTimeout
,提供了对超时的广泛支持。
假设我们希望测试代码在一秒内执行完毕,可以写如下测试用例
@Test
@DisplayName("超时方法测试")
void test_should_complete_in_one_second() {
Assertions.assertTimeoutPreemptively(Duration.of(1, ChronoUnit.SECONDS), () -> Thread.sleep(2000));
}
这个测试运行失败,因为代码执行将休眠两秒钟,而我们期望测试用例在一秒钟之内成功。但是如果我们把休眠时间设置一秒钟,测试仍然会出现偶尔失败的情况,这是因为测试方法执行过程中除了目标代码还有额外的代码和指令执行会耗时,所以在超时限制上无法做到对时间参数的完全精确匹配