Add unit testing framework, based on flexunit 4.0 . To compile and run the tests...
authorAndy Allan <gravitystorm@gmail.com>
Wed, 8 Dec 2010 15:09:42 +0000 (15:09 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Wed, 8 Dec 2010 15:09:42 +0000 (15:09 +0000)
15 files changed:
build.properties.template
build.xml
lib/flexUnitTasks-4.0.0.jar [new file with mode: 0644]
lib/flexunit-4.0.0.swc [new file with mode: 0644]
lib/flexunit-aircilistener-4.0.0.swc [new file with mode: 0644]
lib/flexunit-cilistener-4.0.0.swc [new file with mode: 0644]
lib/flexunit-flexcoverlistener-4.0.0.swc [new file with mode: 0644]
lib/flexunit-uilistener-4.0.0.swc [new file with mode: 0644]
tests/fakeroot/hxasm [new symlink]
tests/fakeroot/it [new symlink]
tests/fakeroot/net [new symlink]
tests/fakeroot/org [new symlink]
tests/src/AllHalcyonTests.as [new file with mode: 0644]
tests/src/HalcyonTestRunner.mxml [new file with mode: 0644]
tests/src/net/systemeD/halcyon/connection/NodeTest.as [new file with mode: 0644]

index bf6f92a..55fcec5 100644 (file)
@@ -11,4 +11,12 @@ ASDOC=${FLEX_HOME}/bin/asdoc
 # {$basedir} is a default variable that can be used in any Ant script
 # SRC_DIR =${basedir}/src
 # points to the project's libs directory
-# LIBS_DIR =${basedir}/lib
+LIBS_DIR =${basedir}/lib
+
+test.application.name = HalcyonTestRunner
+
+test.src.dir = ${basedir}/tests/src
+test.fakeroot.dir = ${basedir}/tests/fakeroot
+test.bin.dir = ${basedir}/tests/bin
+report.dir = ${basedir}/tests/report
+report.html.dir = ${basedir}/tests/report/html
\ No newline at end of file
index 4e2a0c9..cf0c05a 100644 (file)
--- a/build.xml
+++ b/build.xml
         <!--<echo message="manifests = ${org_classes} ${it_classes} ${hxasm_classes}"/>-->
   </target>
 
+  <!-- ======================================= -->
+  <!-- Unit Test Targets -->
+  <!-- ======================================= -->
+  <target name="compileTestRunner" depends="init" description="Compiles the test runner application.">
+   
+    <!-- Compile TestRunner MXML as a SWF -->
+    <mxmlc file="${test.src.dir}/${test.application.name}.mxml"
+      output="${test.bin.dir}/${test.application.name}.swf">
+     
+      <!--<load-config filename="${FLEX_HOME}/frameworks/air-config.xml" />-->
+
+      <!-- we need to supply source paths for the real source and the test source. But passing
+          the potlatch2 top-level directory causes a problem since that also contains the test source.
+          We could move every source folder (net, org, it and hxasm) into a src/ folder, or alternatively
+          set up a fake root folder in the test folder with symlinks to the four directories concerned.
+          It's a bodge, but it works. -->
+      <source-path path-element="${test.fakeroot.dir}" />
+      <source-path path-element="${test.src.dir}" />
+       
+      <!-- The TestRunner needs the flexunit libraries in the build/libs folder -->
+      <library-path dir="${LIBS_DIR}" append="true">
+         <include name="*.swc" />
+      </library-path>
+
+       
+      <!-- Sets java.awt.headless=true so font compilation works in headless environments -->
+      <compiler.headless-server>true</compiler.headless-server>
+     </mxmlc>
+     
+     <echo message="The ${test.application.name}.swf test runner has been created in ${test.bin.dir}" />
+  </target>
+   
+  <target name="runTestsAndReport" depends="init" description="Launches the test runner, captures results, generates test report artifacts.">
+
+      <mkdir dir="${report.dir}" />
+      <mkdir dir="${report.html.dir}" />
+  
+     <!-- Run FlexUnit Ant Task to execute the unit tests and capture reporting data -->
+     <!-- on linux, make sure that gflashplayer is in your PATH and launches a standalone flashplayer binary -->
+     <taskdef resource="flexUnitTasks.tasks" classpath="${LIBS_DIR}/flexUnitTasks-4.0.0.jar" />
+     <flexunit swf="${test.bin.dir}/${test.application.name}.swf" toDir="${report.dir}"
+       haltonfailure="false" verbose="false" localTrusted="true" player="flash" />
+       
+      <!-- Generate html JUnit-style reports based on test results -->
+      <junitreport todir="${report.dir}">
+        <fileset dir="${report.dir}">
+          <include name="TEST-*.xml" />
+        </fileset>
+        <report format="frames" todir="${report.html.dir}" />
+      </junitreport>
+         
+         <echo message="The unit test reports have been created in ${report.dir}" />
+  </target>
+
+  <target name="test" depends="init, compileTestRunner, runTestsAndReport" description="Compiles unit tests and generates test report artifacts." />
+
 </project>
diff --git a/lib/flexUnitTasks-4.0.0.jar b/lib/flexUnitTasks-4.0.0.jar
new file mode 100644 (file)
index 0000000..a019238
Binary files /dev/null and b/lib/flexUnitTasks-4.0.0.jar differ
diff --git a/lib/flexunit-4.0.0.swc b/lib/flexunit-4.0.0.swc
new file mode 100644 (file)
index 0000000..bf8d0a4
Binary files /dev/null and b/lib/flexunit-4.0.0.swc differ
diff --git a/lib/flexunit-aircilistener-4.0.0.swc b/lib/flexunit-aircilistener-4.0.0.swc
new file mode 100644 (file)
index 0000000..99557a8
Binary files /dev/null and b/lib/flexunit-aircilistener-4.0.0.swc differ
diff --git a/lib/flexunit-cilistener-4.0.0.swc b/lib/flexunit-cilistener-4.0.0.swc
new file mode 100644 (file)
index 0000000..a33f065
Binary files /dev/null and b/lib/flexunit-cilistener-4.0.0.swc differ
diff --git a/lib/flexunit-flexcoverlistener-4.0.0.swc b/lib/flexunit-flexcoverlistener-4.0.0.swc
new file mode 100644 (file)
index 0000000..d9aaf60
Binary files /dev/null and b/lib/flexunit-flexcoverlistener-4.0.0.swc differ
diff --git a/lib/flexunit-uilistener-4.0.0.swc b/lib/flexunit-uilistener-4.0.0.swc
new file mode 100644 (file)
index 0000000..e99403d
Binary files /dev/null and b/lib/flexunit-uilistener-4.0.0.swc differ
diff --git a/tests/fakeroot/hxasm b/tests/fakeroot/hxasm
new file mode 120000 (symlink)
index 0000000..9308ea2
--- /dev/null
@@ -0,0 +1 @@
+../../hxasm/
\ No newline at end of file
diff --git a/tests/fakeroot/it b/tests/fakeroot/it
new file mode 120000 (symlink)
index 0000000..0af9f66
--- /dev/null
@@ -0,0 +1 @@
+../../it/
\ No newline at end of file
diff --git a/tests/fakeroot/net b/tests/fakeroot/net
new file mode 120000 (symlink)
index 0000000..1cbc428
--- /dev/null
@@ -0,0 +1 @@
+../../net/
\ No newline at end of file
diff --git a/tests/fakeroot/org b/tests/fakeroot/org
new file mode 120000 (symlink)
index 0000000..62e1324
--- /dev/null
@@ -0,0 +1 @@
+../../org/
\ No newline at end of file
diff --git a/tests/src/AllHalcyonTests.as b/tests/src/AllHalcyonTests.as
new file mode 100644 (file)
index 0000000..a4507fd
--- /dev/null
@@ -0,0 +1,12 @@
+package {
+
+    import net.systemeD.halcyon.connection.NodeTest;
+
+    [Suite]
+    [RunWith("org.flexunit.runners.Suite")]
+    public class AllHalcyonTests {
+
+       public var nodeTest:NodeTest;
+
+    }
+}
diff --git a/tests/src/HalcyonTestRunner.mxml b/tests/src/HalcyonTestRunner.mxml
new file mode 100644 (file)
index 0000000..1b41a20
--- /dev/null
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<mx:Application
+  xmlns:mx="http://www.adobe.com/2006/mxml"
+  xmlns:flexUnitUIRunner="http://www.adobe.com/2009/flexUnitUIRunner"
+  minWidth="955" minHeight="600"
+  creationComplete="onCreationComplete();">
+
+  <mx:Script>
+  <![CDATA[
+  
+      import org.flexunit.internals.TextListener;
+      import org.flexunit.internals.TraceListener;
+      import org.flexunit.listeners.CIListener;
+      import org.flexunit.listeners.UIListener;
+      import org.flexunit.runner.FlexUnitCore;
+      private var core:FlexUnitCore;
+      
+      private function onCreationComplete():void
+      {
+      core = new FlexUnitCore();
+      // If you don't need graphical test results, comment out the line
+      // below and the MXML declaring the TestRunnerBase.
+      core.addListener( new UIListener( uiListener ) );
+      // Listener to support continuous integration servers
+      core.addListener( new CIListener() );
+      // If you would like to see text output in verbose mode,
+      // uncomment either of the follow listeners
+      //core.addListener( new TraceListener() ); // For AS3 Projects
+      //core.addListener( TextListener.getDefaultTextListener( LogEventLevel.DEBUG ) ); // For Flex Projects
+      core.run( AllHalcyonTests );
+      }
+  ]]>
+  </mx:Script>
+
+  <flexUnitUIRunner:TestRunnerBase id="uiListener" width="100%" height="100%" />
+
+</mx:Application>
diff --git a/tests/src/net/systemeD/halcyon/connection/NodeTest.as b/tests/src/net/systemeD/halcyon/connection/NodeTest.as
new file mode 100644 (file)
index 0000000..b7eacff
--- /dev/null
@@ -0,0 +1,30 @@
+package net.systemeD.halcyon.connection {
+
+    import org.flexunit.Assert;
+    import net.systemeD.halcyon.connection.Node;
+    import net.systemeD.halcyon.connection.UndoableAction;
+
+    public class NodeTest {
+
+    
+      [Test]
+      public function dummy():void {
+          Assert.assertEquals(10,10);
+      }
+
+      [Test]
+      public function newNode():void {
+          var n:Node = new Node(1,1,{},true,5,10);
+          Assert.assertEquals(n.lat, 5);
+      }
+
+      [Test]
+      public function moveNode():void {
+          var n:Node = new Node(1,1,{},true,5,10);
+          n.setLatLon(14,41, function(action:UndoableAction):void { action.doAction(); });
+          Assert.assertEquals(n.lat, 14);
+          Assert.assertEquals(n.lon, 41);
+      }
+     
+    }
+}