0
我想使用Junit測試來測試我用slick2d編寫的遊戲(它建立在LWJGL上)(可能單元測試是個壞主意,但我選擇它作爲我的作業)我在單獨的線程中運行遊戲並模擬鼠標點擊並進行斷言測試。一直持續到我有多個測試功能。 (我將「test」函數複製並粘貼到第二個函數中)在第二個測試函數中創建另一個gameContainer和實際遊戲會導致我的測試崩潰。我想我需要在測試後重置遊戲環境,但我不知道如何。油滑單元測試 - 重新運行遊戲時出錯
這裏是我的測試:(我簡化它儘可能地)
@Test
public void test() throws InterruptedException {
Thread t = new Thread(new engineTest());
t.start();
Thread.sleep(3000); // wait for game to initialize
// Game simulation and asserts are here
t.interrupt();
Thread.sleep(1000);
}
我嘗試了許多變化,包括調用.exit()和.destroy()遊戲容器,但它再次崩潰。
和線程功能是在這裏:
public class engineTest implements Runnable {
@Override
public void run() {
SapiensSlick.main(null); // SapiensSlick is name of the game
}
}
而且我得到這個錯誤時,第二個功能是在進步:
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
java: ../../src/xcb_io.c:179: dequeue_pending_request: Předpoklad „!xcb_xlib_unknown_req_in_deq「 nesplněn.
hello
Tue Apr 28 10:50:07 CEST 2015 INFO:Slick Build #237
Testsuite: JunitTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec
Testcase: JunitTest:test: Caused an ERROR
Forked Java VM exited abnormally. Please note the time in the report does not reflect the time until the VM exit.
junit.framework.AssertionFailedError: Forked Java VM exited abnormally. Please note the time in the report does not reflect the time until the VM exit.
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
我沒有找到解決方案,所以我最終在一個線程中運行遊戲並在另一個線程中測試。 –