How do I add the testng.xml file to the root of the *-tests.jar file in my Appium Java TestNG test package for AWS Device Farm?

Last updated: 2021-12-01

I want to configure Appium Java TestNG tests for my AWS Device Farm project. However, I need to add a testng.xml file into the root of the *-tests.jar file in my Appium test package first. How do I do that?

Short description

Configure the Apache Maven pom.xml file to package your testng.xml file into the root of your Appium test package's *-tests.jar file.

Note: In Device Farm's standard test environment, only a subset of the features in the testng.xml file are supported. Use the custom test environment if your project requires any of the following testng.xml file features:

  • Priority
  • 'include' and 'exclude' tags
  • Complex grouping
  • Any TestNG parameters defined in your testng.xml file


1.    In your Apache Maven pom.xml file, verify that the testResources tag includes the following directory: src/test/resources. If you don't see the directory, add the following directory configuration to the file:


Note: You can specify another directory to use for this procedure. If you choose to use another directory, make sure that you use that same directory in steps 2 and 3.

2.    Add your testng.xml file to your pom.xml file's src/test/resources directory.

3.    (Optional) To run tests locally, add the following Maven Surefire plugin to your pom.xml file's <plugins> list.

       <suiteXmlFiles> <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile></suiteXmlFiles>

Note: It's a best practice to run tests locally before uploading projects to Device Farm. The Maven Surefire plugin allows your pom.xml file to reference your testng.xml file during local tests.

4.    Clean your pom.xml file's target directory and repackage your test files by running the following Maven command:

$ mvn clean package -DskipTests=true

Note: The DskipTests=True value specifies that the build won't run the unit tests.

The command creates a file in your pom.xml file's target directory. This zip file is your Appium test package and includes your testng.xml file in the root of its *-tests.jar file.

5.    Verify that your testng.xml file is in the root of your Appium test package's *-tests.jar file by running one of the following commands:

To see a snapshot of files in your *-tests.jar file, run the following jar command:

$ jar tvf foo-1.0.0-SNAPSHOT-tests.jar


To extract all of the files in your *-tests.jar file into a folder, run the following unzip command:

$ unzip foo-1.0.0-SNAPSHOT-tests.jar -d sampletestsjarcontents

You can now upload your test package to Device Farm and create a test run using your app and the file.