mardi 28 avril 2015

Slick unit test - error when re-running game

I want to test my game written in slick2d (which is build on LWJGL) using Junit test.(maybe it's bad idea to do unit test, but I chose it as my homework.) I run the game in separate thread and simulate mouse clicking and do assert tests. It goes well until I have more than one test function. (I copied and pasted the "test" function to second function) Creating another gameContainer and the actual game in second test function causes my test to crash. I think I need somehow reset the game context after tests, but i have no idea how.

Here is my test: (I simplified it as much as possible)

 @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);
}

I tried many variations including calling .exit() and .destroy() to the game container, but it crashed again.

And the thread function is here:

public class engineTest implements Runnable {

  @Override
  public void run() {
      SapiensSlick.main(null); // SapiensSlick is name of the game 
  }
}

And I get this error when second function is in progress:

[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)

Aucun commentaire:

Enregistrer un commentaire