| <html> |
| <head> |
| <title>TestNG - Welcome</title> |
| <script type="text/javascript" src="banner.js"></script> |
| <link rel="stylesheet" href="testng.css" type="text/css" /> |
| </head> |
| <body> |
| |
| <script type="text/javascript"> |
| displayMenu("index.html") |
| </script> |
| |
| |
| <h2 >TestNG</h2> |
| <h3 align="center" style="border-bottom: none;background:none;"><i>"Testing, the Next Generation"</i></h3> |
| <p align="right"><font size="-2"><em>Cédric Beust (cedric at beust.com)<br> |
| Alexandru Popescu (the.mindstorm at gmail.com)<br> |
| Current version: 5.1<br> |
| Created: April 27th, 2004<br> |
| Last Modified: August 17th, 2006 </em></font></p> |
| <p>TestNG is a testing framework inspired from JUnit and NUnit but introducing |
| some new functionalities that make it more powerful and easier to use, such as:</p> |
| <ul> |
| <li>JDK 5 Annotations (JDK 1.4 is also supported with JavaDoc annotations). |
| </li> |
| <li>Flexible test configuration. |
| </li> |
| <li>Support for data-driven testing (with <tt>@DataProvider</tt>).</li> |
| <li>Support for parameters.</li> |
| <li>Allows distribution of tests on slave machines.</li> |
| <li>Powerful execution model (no more <tt>TestSuite</tt>). |
| </li> |
| <li>Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, |
| etc...). |
| </li> |
| <li>Embeds BeanShell for further flexibility. |
| </li> |
| <li>Default JDK functions for runtime and logging (no dependencies). |
| </li> |
| <li>Dependent methods for application server testing.</li> |
| </ul> |
| <p>TestNG is designed to cover all categories of tests: unit, functional, |
| end-to-end, integration, etc...</p> |
| <p>I started TestNG out of frustration for some JUnit deficiencies which I have |
| documented on my weblog <a href="http://jroller.com/page/cbeust/20030425">here</a>, |
| <a href="http://www.jroller.com/page/cbeust/20030317">here</a>, <a href="http://www.beust.com/weblog/archives/000173.html">here</a> and in |
| particular, <a href="http://www.beust.com/weblog/archives/000082.html">here</a> |
| Reading these entries might give you a better idea of the goal I am trying to |
| achieve with TestNG. You can also check out a quick |
| <a href="http://www.beust.com/weblog/archives/000176.html">overview of the main |
| features</a> and an <a href="http://www.beust.com/weblog/archives/000170.html"> |
| article</a> describing a very concrete example where the combined use of several |
| TestNG's features provides for a very intuitive and maintainable testing design.</p> |
| <p>Here is a very simple test:</p> |
| |
| <pre class="code"> |
| <span class=j_eclipse_keyword>package example1;</span> |
| |
| <span class=j_eclipse_keyword>import</span> <span class=j_eclipse_pkgname>org.testng</span>.<span class=j_eclipse_pkgname>annotations</span>.<span class=j_eclipse_pkgname>*</span>; |
| |
| <span class=j_eclipse_keyword>public</span> <span class=j_eclipse_keyword>class</span> <span class=j_eclipse_classname>SimpleTest</span> { |
| |
| @<span class=j_eclipse_classname>Configuration</span>(beforeTestClass = <span class=j_eclipse_constant>true</span>) |
| <span class=j_eclipse_keyword>public</span> <span class=j_eclipse_typekeyw>void</span> <span class=j_eclipse_methname>setUp</span>() { |
| <span class=j_eclipse_comment>// code that will be invoked when this test is instantiated</span> |
| } |
| |
| @<span class=j_eclipse_classname>Test</span>(groups = { <span class=j_eclipse_string>"fast"</span> }) |
| <span class=j_eclipse_keyword>public</span> <span class=j_eclipse_typekeyw>void</span> <span class="j_eclipse_methname">aFastTest</span>() { |
| <span class="j_eclipse_comment">System.out.println("Fast test");</span> |
| } |
| |
| @<span class=j_eclipse_classname>Test</span>(groups = { <span class=j_eclipse_string>"slow"</span> }) |
| <span class=j_eclipse_keyword>public</span> <span class=j_eclipse_typekeyw>void</span> <span class="j_eclipse_methname">aSlowTest</span>() { |
| <span class="j_eclipse_comment">System.out.println("Slow test");</span> |
| } |
| |
| } |
| </pre> |
| |
| The method <tt>setUp()</tt> will be invoked after the test class has been built and before |
| any test method is run. In this example, we will be running the group |
| fast, so <tt>aFastTest()</tt> will be invoked while <tt>aSlowTest()</tt> will be |
| skipped.<p> |
| <!------------------------------------- |
| |
| WRITING A TEST |
| |
| ------------------------------------> |
| |
| Things to note:</p><ul> |
| <li>No need to extend a class or implement an interface.</li><li>Even though the example above uses the JUnit conventions, our methods |
| can be called any name you like, it's the annotations that tell TestNG what |
| they are.</li><li>A test method can belong to one or several groups. These groups will be |
| used at runtime to determine what test methods should be invoked..</li></ul> |
| |
| <p> |
| |
| Once you have compiled your test class into the <tt>build</tt> directory, you |
| can invoke your test with the command line, an ant task (shown below) or an XML |
| file:<pre class="code"><<span class="tag">project </span><span class="attribute">default="test"</span>> |
| |
| <<span class="tag">path </span><span class="attribute">id="cp"</span>> |
| <<span class="tag">pathelement </span><span class="attribute">location="lib/testng-testng-4.4-jdk15.jar"</span>/> |
| <<span class="tag">pathelement </span><span class="attribute">location="build"</span>/> |
| <<span class="tag">/path</span>> |
| |
| <<span class="tag">taskdef </span><span class="attribute">name="testng" classpathref="cp" |
| classname="org.testng.TestNGAntTask" /</span>> |
| |
| <<span class="tag">target </span><span class="attribute">name="test"</span>> |
| <<span class="tag">testng </span><span class="attribute">classpathref="cp" groups="fast"</span>> |
| <<span class="tag">classfileset</span><span class="attribute"> dir="build" includes="example1/*.class"</span>/> |
| <<span class="tag">/testng</span>> |
| <<span class="tag">/target</span>> |
| |
| <<span class="tag">/project</span>></pre>Use ant to invoke it:<pre class="code"> |
| c:> ant |
| Buildfile: build.xml |
| |
| test: |
| [testng] Fast test |
| [testng] =============================================== |
| [testng] Suite for Command line test |
| [testng] Total tests run: 1, Failures: 0, Skips: 0 |
| [testng] =============================================== |
| |
| |
| BUILD SUCCESSFUL |
| Total time: 4 seconds</pre><a name="browse_results" />Then you can browse the |
| result of your tests:<pre class="code"> |
| start test-output\index.html <em>(on Windows)</em></pre> |
| <h3><a name="requirements">Requirements</a></h3> |
| <p>TestNG runs on JDK 1.4 and 5. The examples shown in this |
| documentation assume JDK 5 and therefore, use JDK 5 annotations, but they |
| can easily be translated to JDK 1.4 JavaDoc-type annotations. See the JDK |
| 1.4 section for details.</p> |
| |
| <h3><a name="mailing-lists">Mailing-lists</a></h3> |
| <p>The users mailing-list can be found in two different places:</p> |
| <ul> |
| <li>As an email mailing-list on |
| <a href="http://groups-beta.google.com/group/testng-users/">Google Groups</a>.</li> |
| <li>As a <a href="http://testng.org/forums">Web |
| forum</a>, kindly hosted by <a href="http://opensymphony.com">Open Symphony</a>.</li> |
| </ul> |
| <p>The Web forum and the mailing-list are connected to each other, so you only |
| need to subscribe to one. More specialized mailing-lists (developers, |
| issues, cvs, etc...) are |
| <a href="https://testng.dev.java.net/servlets/ProjectMailingListList">available |
| at Java.net.</a></p> |
| <h3><a name="locations-projects">Locations of the projects</a></h3> |
| <p>If you are interested in contributing to TestNG or one of the IDE plug-ins, |
| you will find them in the following locations:</p> |
| <ul> |
| <li><a href="http://code.google.com/p/testng/">TestNG</a></li> |
| <li><a href="http://testng-eclipse.dev.java.net">Eclipse plug-in</a></li> |
| <li><a href="http://www.javaforge.com/proj/summary.do?proj_id=4">IDEA |
| IntelliJ plug-in</a></li> |
| <li><a href="http://blogs.sun.com/xzajo?entry=test_ng_plugin_for_netbeans"> |
| NetBeans plug-in</a></li> |
| </ul> |
| <h3><a name="bug-reports">Bug reports</a></h3> |
| <p>The TestNG project is administered by |
| <a href="http://jira.opensymphony.com/browse/TESTNG">OpenSymphony's JIRA</a> and |
| you can file a bug report |
| <a href="http://jira.opensymphony.com/secure/CreateIssue!default.jspa">here</a>.</p> |
| |
| <!------------------------------------- |
| |
| REQUIREMENTS |
| |
| ------------------------------------> |
| <p>For more information, you can either <a href="download.html">download TestNG</a>, |
| read the <a href="documentation-main.html">manual</a> or browse the links at the |
| <a href="#top">top</a>.</p> |
| |
| </body> |
| |
| </html> |