A JUnit test runner that runs test methods in a LibGDX ApplicationListener. This means all the Gdx.* statics are initialised and available to use.
@RunWith(QuarantiningRunner.class)
@Quarantine({"com.badlogic", "com.binarytweed.libgdx.test", "com.yourgame.package"})
@DelegateRunningTo(LibGdxTestRunner.class)
public class MyLibGdxTest
{
@Test
public void loadTexture()
{
Texture texture = new Texture("files/whatever.png");
assertThat(texture, notNullValue());
}
...- Annotate your test class with
@RunWith(QuarantiningRunner.class). This will use aRunnerthat loads classes specified below with a separateClassLoaderfor each test. - Use
@Quarantine("com.badlogic", "com.binarytweed.libgdx.test", "com.yourgame.package")to specify that classes from these packages will be loaded in a separateClassLoader, so that theGdx.*statics will be reset between tests. Add the package/classnames of things that will access Gdx.*, as otherwise they will looking at the Gdx.* loaded by the default classloader, instead of the quarantined one. - Specify
@DelegateRunningTo(LibGdxTestRunner.class)so thatQuarantiningRunnerknows to useLibGdxTestRunner, which runs your tests in anApplicationListenerinstance.
If your assets are on the (test) classpath, they should just work. If you want to use separate test assets, you can go Maven-tastic and stick them in src/test/resources/.
- The ApplicationListener's config is hardcoded. Please raise an issue letting me know which aspects you want to be parameterisable
- Tests won't pass on a headless system
- Only the LWJGL backend is supported. If you need any other backend, raise an issue and we can see what's possible.