I found the answer on this BitBucket repo. The README gives a nice explanation of how to implement this using Gradle.
Basically, you just add GdxTestRunner.java from that repo, and then add a @RunWith
to each of your test files:
@RunWith(GdxTestRunner.class)
public class MyClassTest {
...
}
Then in your root level build.gradle
file, add something like this to your core
dependencies:
testCompile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
testCompile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
testCompile "com.badlogicgames.gdx:gdx-bullet:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-desktop"
Obviously the box2d
and bullet
dependencies are only necessary if you are using those libraries.
On the BitBucket repo README, the example includes both
testCompile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
and
compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
I don't think it is necessary to include this for compile
, and if I correctly understand how Gradle works, it will actually slow down your build.