1

I have a LibGDX project with some tests. The structure is as follow:

  • core/src -> for my java sources code
  • core/test -> for my tests source code
  • core/assets -> for all my assets

When I run the tests from eclipse, they all go green but whenever I try to run them from the gradle command line (./gradlew test) I get an error with the assets folder. I believe this is because the tests are not launched from the assets folder as it is from eclipse.
How can I solve this problem ? Is there a way to tell gradle to use core/assets as the workspace directory when running the tests ?

Here is the error I get:
com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load dependencies of asset: myasset.png

Django
  • 110
  • 7
  • First i beg my pardon because I thought you are generating project from old setup tool, for the gradle based setups it will create assets folder in core, so can you provide some code from where you try to access those assets – Digvijaysinh Gohil Nov 10 '17 at 11:31
  • With the project structure described above lets say I have a sprite called "myTexture.png" under *core/assets/MyTexture* Somewhere in my code I write : `assets.load("sprite/myTexture.png", Texture.class);` (Notice how I omitted the "assets" folder). This will work fine if I launch the tests from eclipse. But from the gradle command line this will result as the path error described above. In order to make it work under gradle I have to call: `assets.load("assets/sprite/myTexture.png", Texture.class);` It will work then under gradle but no more in eclipse. – Django Nov 11 '17 at 19:39
  • That why I was asking a way to tell gradle to run the test from the assets folder. Or maybe I am doing it wrong ? – Django Nov 11 '17 at 19:39

1 Answers1

0

I found a way to achieve what I wanted. I post my solution here for anyone that might need it. There is a property named workingDir for the test task in gradle. So I just needed to set it to the right folder. Inside the build.gradle file of your project (the root folder) just add the following section:

project(":core") {
    apply plugin: "java"
    // Add the following test section
    test{
       workingDir= new File("/assets")
    }
    // Rest of the file
}

That's it! My tests are running green from the command line now.

brass monkey
  • 5,841
  • 10
  • 36
  • 61
Django
  • 110
  • 7