I'm using Junit under Ant to perform Selenium Test.My test cases need to read files which contain test data(in order to accomplish data driven test). I don't mind embedding the file names in the test cases, but I'd like to have the name of the directory where the data files are stored parameterized in the build.xml file.

What's the best way to pass information like that from build.xml down into the test cases? Is it a good idea to use ant property? Is it possible to inject Junit4 parameter from build.xml?

share|improve this question

45% accept rate
feedback

1 Answer

The junit task accepts nested sysproperty elements.

<junit fork="no">
  <sysproperty key="mydatadir" value="${whatever}"/>
  ...
</junit>

You can access these from within your tests using System.getProperty().

share|improve this answer
is there no problem if the parallel tests uses the same property (sysproperty)? Is it possible to inject test data into JUnit parameters within Ant instead of retrieving data inside the test case? – user405458 Sep 23 '10 at 9:55
Do you need different values in each parallel thread? You have the junit task jvmarg element, which can have a similar effect to sysproperty - don't see any advantage to that though. Not obvious to me what other options of the task can be used to pass data in. – martin clayton Sep 23 '10 at 10:13
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.