views:

73

answers:

1

Hi,

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?

Thanks for your help

+1  A: 

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().

martin clayton
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?
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