Replaying Keyword-Driven Tests with Apache Ant

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

To replay keyword-driven tests with Apache Ant, for example to generate HTML reports of the test runs, use the KeywordTestSuite class.

  1. To execute a keyword-driven test with Apache Ant, create a JUnit test suite with the @KeywordTests annotation. For example, if you want to execute the keyword-driven test My Keyword-Driven Test, create the JUnit test suite MyTestSuite as follows:
    @RunWith(KeywordTestSuite.class)
    @KeywordTests({ "My Keyword-Driven Test" })
    public class MyTestSuite {
    
    }
  2. Open the build.xml file of the Silk4J project, which includes the keyword-driven test.
  3. To execute the keyword-driven test, add the following target to the build.xml file:
    <target name="runTests" depends="compile">
      <mkdir dir="./reports"/>
      <junit printsummary="true" showoutput="true" fork="true">
        <classpath>
          <fileset dir="${output}">
            <include name="**/*.jar" />
          </fileset>
          <fileset dir="${buildlib}">
            <include name="**/*.jar" />
          </fileset>
          <fileset dir="C:/Program Files (x86)/Silk/SilkTest/ng/KeywordDrivenTesting">
            <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">
        <classpath>
          <fileset dir="${output}">
            <include name="**/*.jar" />
          </fileset>
          <fileset dir="${buildlib}">
            <include name="**/*.jar" />
          </fileset>
          <fileset dir="C:/Program Files (x86)/Silk/SilkTest/ng/KeywordDrivenTesting">
            <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.