1

In short, I want to know, is there a JVM command-line option to change the starting working directory? If it's important, I'm running jdk1.6.0_24.

Background:

I am using a tool called Robolectric for Eclipse to test Android applications on the host PC without emulation. Robolectric requires a test project be created, but the tests themselves to be run from the Android project under test. This is accomplished by from Eclipse, setting the run configuration to the project under test in the setting: "Run all tests in the selected project, package or source folder."

I want to do this from the JVM command line options, if possible, because another tool I use, Infinitest, doesn't allow you to specify the working directory of the tests. It does, however, let you specify JVM command-line options.

Workaround:

Until I find a better workaround, a successful kluge has been to copy the AndroidManifest.xml and res folder from the Android project.

Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246

3 Answers3

8

In Java SE, the "current directory" is put into the system property user.dir.

Manually override this value using a -D option might work:

java -Duser.dir=/some/directory ....

But I don't know if this also applies to the JVM used in Android

  • 3
    Bad idea. Anything I've ever seen about doing this says "don't". It's unreliable at best. Unless of course that's changed in Android, too. But this is just a test suite, right? Not running inside Android? – Ryan Stewart Oct 20 '11 at 23:53
  • 1
    I am using this approach on a regular basis and it works quite well. –  Oct 21 '11 at 07:12
  • 2
    Modifying this variable is not recommended and is unreliable per [this response](http://stackoverflow.com/questions/1234795/why-is-the-user-dir-system-property-working-in-java/1234880#1234880). It didn't work for me. – Jeff Axelrod Oct 21 '11 at 16:27
2

"Current working directory" is an OS concept, not a JVM one, so you'll need to find a solution at that level, such as writing a batch or shell script.

Ryan Stewart
  • 126,015
  • 21
  • 180
  • 199
0

I would look into running the robolectric tests within a Maven build. That makes it way easier to run the tests. Within Eclipse as well. And there is probably infinitest support for Maven as well.

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
  • Infinitest's documentation doesn't indicate support for Maven. I have been playing with sbt, and did successfully build my Android application with it, but haven't yet adopted it into my normal development. I am pretty sure that sbt supports some type of automated test running after a build, which I think would replace infinitest. – Jeff Axelrod Oct 20 '11 at 17:25
  • Yes, that's how I did the build. – Jeff Axelrod Oct 20 '11 at 17:28