Hi nhahn, good to meet you.
I do exactly the same thing, I think its imminently sensible to have automated tests for the whole application (if you call them system tests it calms people down).
I’ve just run some of my JUnit system tests using 3.5.0-stable so we should be able to find a way to make it work. Did you by any chance change from jme3-lwjgl to jme3-lwjgl3? Both work fine with JUnit tests but their threading behaviour is different so the way the game is launched needs to be changed.
I presume your Junit test case and JMonkey game run on different threads?
I boot the real application as follows
static CrossThreadGameStarter starter = new CrossThreadGameStarter();
later
starter.executeStartCommand( () -> Main.main(new String[]{TEST_MODE}));
CrossThreadGameStarter is a nasty busy wait loop and a static call to somewhere my Main application class puts itself but it works
public class CrossThreadGameStarter {
private Executor executor = Executors.newSingleThreadExecutor();
/**
* Will start up One million worlds (given the correct command)
* then will block the calling thread until it is initialised.
* At which point the method will return
*/
public void executeStartCommand(Runnable startCommand){
Main.main = null; // <--- This Main.main probably isn't a good idea and is specific to my set up
executor.execute( startCommand );
while(Main.main == null || !Main.main.hasBeenInitialised){
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
Edit
Looking at your example source though. While its perfectly fine to unit test a whole SimpleApplication, having the test actually be a SimpleApplication is a little surprising. I would have expected a seperate test class that spun up a thread and called the main method of your simpleApplication (and did that once per test). I am increasingly convinced that this is a jme3-lwjgl vs jme3-lwjgl3 problem though. As in jme3-lwjgl the app.start();
returned having spawned a thread, while in jme3-lwjgl3 it doesn’t. See LWJGL3 JME doesn't return from app.start() but LWJGL2 did for more