6

I'm trying to integrate Cobertura into our test environment to be able to capture code coverage information. The tests are run from ant scripts using ANT junit tasks, and there are more than 50 ant script files (build.xml) with one or more junit task definitions.

As per the Cobertura doc, the junit tests have to be given the path of the cobertura coverage data file through the sysproperty nested element of the junit task. What it means to me is that I will need to update all those 50+ files to specify a sysproperty element for the junit tasks, which I plan to do as a last resort.

I'm running my tests in Linux (CentOS) and I would like to know if there is a way to specify a global system property (-Dxxx=yyy) so that the system property is made available to all java applications running in the system.

-EDIT-
The junit tests are run in a forked JVM. <junit fork="yes" ...

srkavin
  • 1,152
  • 7
  • 17
  • Depending on which ide you use, it should be pretty straightforward to refactor them quickly. Also you can try the ant input task, if that will help. – r0ast3d Nov 16 '11 at 21:06
  • @r0ast3d As I'd mentioned, that's the way I'm going to take if I don't find another simple solution which doesn't require modifying the scripts. – srkavin Nov 16 '11 at 21:57

2 Answers2

8

You can try to set ANT_OPTS environment variable.


ANT_OPTS - command-line arguments that should be passed to the JVM. For example, you can define system properties or set the maximum Java heap size here.


-EDIT-

You have to set _JAVA_OPTIONS environment variable. Here and here there is some information about it.

szhem
  • 4,672
  • 2
  • 18
  • 30
  • +1 Thanks. It works if I run the tests within the same VM, but I need to run my tests in a forked VM. I have updated the question. – srkavin Nov 16 '11 at 21:55
  • Just updated my answer. You have to set `_JAVA_OPTIONS` environment variable to define default JVM properties. – szhem Nov 16 '11 at 22:35
0

alternatively set environment variable and in your ant script use :

<property environment="env"/>
<echo>${env.yourEnvVariable}</echo>
...

The advantage over using ANT_OPTS (which is primarily meant for ant internal settings, like f.e. VM parameters..) is the possibility for userspecific settings if using user environment variables whereas ANT_ARGS is "static" for all ant scripts.

Rebse
  • 10,307
  • 2
  • 38
  • 66