Replaying Tests with Apache Ant

To perform the actions described in this topic, ensure that Apache Ant is installed on your machine.

To replay tests with Apache Ant, for example to generate HTML reports of the test runs, use the SilkTestSuite class. To replay keyword-driven tests with Apache Ant, use the KeywordTestSuite class. For additional information on replaying keyword-driven tests with Apache Ant, see Replaying Keyword-Driven Tests with Apache Ant.

  1. To execute tests with Apache Ant, create a JUnit test suite with the @SuiteClasses annotation. For example, if you want to execute the tests in the classes MyTestClass1 and MyTestClass2 , which are located in the same Silk4J project, create the JUnit test suite MyTestSuite as follows:
    @RunWith(SilkTestSuite.class)
    @SuiteClasses({ MyTestClass1.class, MyTestClass2.class})
    public class MyTestSuite {
    
    }
  2. Open the build.xml file of the Silk4J project, which includes the tests.
  3. To execute the tests, add the following target to the build.xml file:
    Note: The following code sample works only with Silk4J projects that are created with Silk Test 15.5 or later.
    <target name="runTests" depends="compile">
      <condition property="agentRmiHost" value="">
        <not>
          <isset property="agentRmiHost" />
        </not>
      </condition>
      <condition property="silktest.configurationName" value="">
        <not>
          <isset property="silktest.configurationName" />
        </not>
      </condition>
      <mkdir dir="./reports"/>
      <junit printsummary="true" showoutput="true" fork="true">
        <sysproperty key="agentRmiHost" value="${agentRmiHost}" />
        <sysproperty key="silktest.configurationName" value="${silktest.configurationName}" />
        <classpath>
          <fileset dir="${output}">
            <include name="**/*.jar" />
          </fileset>
          <fileset dir="${buildlib}">
            <include name="**/*.jar" />
          </fileset>
        </classpath>
    
        <test name="MyTestSuite" todir="./reports"/>
      </junit>
    </target>
    For additional information about the JUnit task, see https://ant.apache.org/manual/Tasks/junit.html.
  4. Optional: To create XML reports for all tests, add the following code to the target:
    <formatter type="xml" />
  5. Optional: To create HTML reports out of the XML reports, add the following code to the target:
    <junitreport todir="./reports">
      <fileset dir="./reports">
        <include name="TEST-*.xml" />
      </fileset>
      <report format="noframes" todir="./report/html" />
    </junitreport>
    For additional information about the JUnitReport task, see https://ant.apache.org/manual/Tasks/junitreport.html. The complete target should now look like the following:
    <target name="runTests" depends="compile">
    
      <mkdir dir="./reports"/>
      <junit printsummary="true" showoutput="true" fork="true">
        <sysproperty key="agentRmiHost" value="${agentRmiHost}" />
        <sysproperty key="silktest.configurationName" value="${silktest.configurationName}" />
        <classpath>
          <fileset dir="${output}">
            <include name="**/*.jar" />
          </fileset>
          <fileset dir="${buildlib}">
            <include name="**/*.jar" />
          </fileset>
        </classpath>
    
        <formatter type="xml" />
        
        <test name="MyTestSuite" todir="./reports"/>
      </junit>
      <junitreport todir="./reports">
        <fileset dir="./reports">
          <include name="TEST-*.xml" />
        </fileset>
        <report format="noframes" todir="./report/html" />
      </junitreport>
    </target>
  6. To run the tests from Eclipse, perform the following actions:
    1. In the Package Explorer, right-click the build.xml file.
    2. Select Run As > Ant Build ....
    3. In the Targets tab of the Edit Configuration dialog box, check runTests.
    4. Click Run.
You can also execute the tests from the command line or from a CI server. For additional information, see https://ant.apache.org/manual/running.html and Replaying Tests from a Continuous Integration Server in the Silk4J Help.