Ant target to automatically download and install TestNG

Paul Sandoz paul.sandoz at oracle.com
Fri Aug 24 10:50:07 PDT 2012


Hi,

Below is a simple patch that provides an ant target to automatically download and install TestNG.

I suspect this area will likely change but in the interim i suppose "every little bit helps" for those running the tests for the first time.

Paul.

diff -r 6b67e68ac62e test-ng/README
--- a/test-ng/README	Wed Aug 22 17:38:46 2012 -0700
+++ b/test-ng/README	Fri Aug 24 19:41:33 2012 +0200
@@ -1,5 +1,12 @@
-Running the TestNG based unit tests requires downloading the TestNG
-library and placing its jar file into the lib subdirectory:
+Running the TestNG based unit tests requires the TestNG library
+and placing its jar file in the lib subdirectory.
+
+This can be achieved by executing the following ant task:
+
+   # download and install TestNG
+   ant testng-install
+
+Or manually as follows:
 
    # download and install TestNG
    wget http://testng.org/testng-6.5.2.zip
@@ -7,6 +14,10 @@
    mkdir lib
    cp testng-6.5.2/testng-6.5.2.jar lib
 
+The unzipped hierarchy can be removed.
+
+Run the test as follows:
+
    # run tests
    ant test
 
diff -r 6b67e68ac62e test-ng/build.xml
--- a/test-ng/build.xml	Wed Aug 22 17:38:46 2012 -0700
+++ b/test-ng/build.xml	Fri Aug 24 19:41:33 2012 +0200
@@ -10,18 +10,36 @@
     <property name="lambda.metafactory" value="" />
     <property name="generated.dir" value="gen-separate"/>
 
-    <property name="lib.testng.jar" value="${lib.dir}/testng-6.5.2.jar"/>
+    <property name="testng" value="testng-6.5.2"/>
+    <property name="testng.jar" value="${testng}.jar"/>
+    <property name="testng.zip" value="${testng}.zip"/>
+    <property name="lib.testng.jar" value="${lib.dir}/${testng.jar}"/>
     <property name="lib.tools.jar" value="${java.home}/../lib/tools.jar"/>
 
+    <target name="-check-testng-install" unless="testng.library.exists">
+        <available property="testng.library.exists" file="${lib.testng.jar}"/>
+    </target>
+    
+    <target name="testng-install" depends="-check-testng-install" unless="${testng.library.exists}">
+        <mkdir dir="${lib.dir}"/>
+        <get src="http://testng.org/${testng.zip}" dest="${lib.dir}" skipexisting="true"/>
+        <unzip src="${lib.dir}/${testng.zip}" dest="${lib.dir}">
+            <patternset>
+                <include name="${testng}/${testng.jar}"/>
+            </patternset>
+            <mapper type="flatten"/>
+        </unzip>
+    </target>
+
     <path id="test.class.path">
         <pathelement location="${test.classes.dir}" />
         <pathelement location="${lib.testng.jar}"/>
         <pathelement location="${lib.tools.jar}"/>
     </path>
-
-    <taskdef name="testng" classpathref="test.class.path" classname="org.testng.TestNGAntTask" />
-
+    
     <target name="prepare">
+        <taskdef name="testng" classpathref="test.class.path" classname="org.testng.TestNGAntTask"/>
+        
         <mkdir dir="${build.dir}"/>
         <mkdir dir="${test.classes.dir}"/>
         <mkdir dir="${test.reports.dir}"/>


More information about the lambda-dev mailing list