- Extract Automation Library Package to your local file system
dtTaskDefs.xml(defines all Ant Task) and
com.dynatrace.diagnostics.automation.jar(the actual automation library)
As a prerequisite to use the Dynatrace tasks in your Ant build, import the Dynatrace task definitions in your build.xml. The dtTaskDefs.xml file assumes that the com.dynatrace.diagnostics.automation.jar is located in the same directory
Before you run your tests (JUnit, TestNG, NUnit), use the DtStartTest Ant task to register a new test run on the Dynatrace Server and pass additional metadata like the major/minor version. This way, the Dynatrace Server is able to identify PurePaths that originate in the same test run and allows you to perform parallel test runs.
As a best practice, we recommend to define the individual bits of metadata as separate properties so they can be easily changed afterwards. For example, we can rely on the fact that properties in Ant are immutable (they cannot be changed after a value has been assigned), so we can define default values in the script and overwrite them when the build is run through a CI server.
After setting these properties, you can call DtStartTest before you actually run the tests. In this example, a target named "test" is called that depends on compiling code and tests first, and then executes the JUnit tests. At the beginning of this target, you call DtStartTest and pass in the various parameter defined before:
What happens here is that DtStartTest uses the Dynatrace Server REST interface to register a test run on the server, and sets a property called dtTestrunID that contains an ID used to by the agent to tag all PurePaths belonging to a test run. This ID has to be passed to the dynaTrace agent instrumenting the JVM running the tests as a parameter called optionTestRunIdJava (see example below).
Now that you have told Dynatrace about the tests to come, you can move forward with actually executing the tests. To make sure our integration works, you have to make sure that the JVM running the tests has
a) a Java agent injected and
b) gets the test run ID set in the optionTestRunIdJava parameter.
Therefore, it is important to use fork="on" on the JUnit task as otherwise the tests would execute in the JVM running Ant, and you would not get an agent injected. The other configuration of the junit task looks just like it would without dynaTrace, we define a classpath and a fileset:
And that's it! You can continue with your build script as you usually would, for example with building an HTML report of JUnit results and bundling up artifacts. The full test target looks as follows: