Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass parameters to a Junit test from Ant?

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?

like image 645
user405458 Avatar asked Sep 23 '10 09:09

user405458


People also ask

Can JUnit test method have parameters?

JUnit allows you to use parameters in a tests class. This class can contain multipletest methods and each method is executed with the different parameters provided. It helps developers save time when executing the same tests which differ only in their inputs and expected results.

Can JUnit be integrated with ant?

Learn Maven and Ant the easy way! There are a number of JUnit extensions available. If you are unfamiliar with JUnit, you should download it from www.junit.org and read its manual. This chapter shows how to execute JUnit tests by using Ant. The use of Ant makes it straight forward through the JUnit task.


1 Answers

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

like image 127
martin clayton Avatar answered Sep 23 '22 03:09

martin clayton