Skip to content

iam-here/libgdx-test-runner

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libgdx-test-runner

Build Status

A JUnit test runner that runs test methods in a LibGDX ApplicationListener. This means all the Gdx.* statics are initialised and available to use.

To use (resetting statics between each test class)

@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());
   }
...
  1. Annotate your test class with @RunWith(QuarantiningRunner.class). This will use a Runner that loads classes specified below with a separate ClassLoader for each test.
  2. Use @Quarantine("com.badlogic", "com.binarytweed.libgdx.test", "com.yourgame.package") to specify that classes from these packages will be loaded in a separate ClassLoader, so that the Gdx.* 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.
  3. Specify @DelegateRunningTo(LibGdxTestRunner.class) so that QuarantiningRunner knows to use LibGdxTestRunner, which runs your tests in an ApplicationListener instance.

Assets

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/.

Known Issues

  1. The ApplicationListener's config is hardcoded. Please raise an issue letting me know which aspects you want to be parameterisable
  2. Tests won't pass on a headless system
  3. Only the LWJGL backend is supported. If you need any other backend, raise an issue and we can see what's possible.

About

Runs each JUnit test inside a fresh LibGDX ApplicationListener

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Java 100.0%