Joe Hoffman, Director of Western Region Sales Engineers at dynaTrace, shares the following article on How to Integrate dynaTrace with TestNG.
When testing applications, there’s a variety of tools available in the marketplace to automate this process. TestNG happens to be one of those tools and dynaTrace has out-of-the-box support for TestNG.
To demonstrate TestNG and dynaTrace, we will use a simple example available from the TestNG.org website at http://testng.org/doc/index.html. We will show this example within the context of Eclipse, however Eclipse is just a convenience, not a necessity. Most people use something like ant to invoke their TestNG test suite, however for simplicity we will not discuss ant integration. There are some good examples of that on the dynaTrace Community Portal and product documentation pages.
Our example uses the following test class SimpleTest:
Configure within Eclipse
To get this to work, I start Eclipse, create a new project called MyTestNGExample (I’m not very original), added a new class to it with the code above, and added the TestNG library testng-5.14.10.jar (which I downloaded from TestNG.org). Then I created a
testng.xml file in the root of the MyTestNGExample project that contains the following:
Notice the class name in the xml matches the name of the test class above.
Please see TestNG documentation for more examples.
With this in place, I simply create a new run configuration (called RunTests) and specify org.testng.TestNG as the main class and testng.xml as the program argument. By running the RunTests configuration, I see the output in the eclipse console, namely “Fast test” and “Slow test”.
Execute with dynaTrace
To execute the same RunTests configuration with dynaTrace, simply use the existing Eclipse plugin from dynaTrace, and from the Run with dynaTrace agent menu, simply select the RunTests configuration option. You may have to edit the RunTests configuration under the dynaTrace menu and configure the agent under the dynaTrace Integration tab.
When the SimpleTest runs you will notice the output in the Eclipse console which includes the dynaTrace banner. This indicates that we successfully ran our TestNG sample test with the dynaTrace agent. Now bring up the dynaTrace Client, drill into the profile which was specified in the dynaTrace Integration tab in the last step, and observe the execution results of your tests via the Test Automation Dashlet. Repeated tests are viewed for the selected measure of the selected test. This allows for easy detection of regressions. After 5 (default) executions, an automatic expected value Corridor is calculated and displayed.
How it works
Notice that you didn’t have to do anything special to your TestNG script. This is because dynaTrace is configured out-of-the-box to automatically instrument certain methods within your TestNG based on annotations. Observe the @Test annotation that is used in the test code above. This annotation is observed by dynaTrace to indicate that the associated method should be instrumented at runtime. No test modifications required. Pretty cool huh?
Of course your TestNG test is probably more complex and likely invoked by something like Ant or NAnt. There’s additional integration opportunities with dynaTrace when using Ant/NAnt which automate many of the steps. This is outside the scope of this discussion, but details can be found on the dynaTrace Community
- dynaTrace in Continuous Integration - The Big Picture
- Test Automation
- Browser Test Automation
- Automation Library (Ant, Maven) for Dynatrace
With the information in this writeup, you should be well on your way to using dynaTrace with your TestNG based testing environment. The integration is easy (even I got it working), and the visibility across your CI driven tests is incredible with the TestAutomation dashlet.
Not Logged In? Customers and AJAX Edition Users Login with your Community Account