views:

61

answers:

0

Hi.

i am trying to create a build.xml script that cleans, builds and creates a apk file of a Junit android test project that i have created.

the steps i want to achieve in my build file is this:

clean

build

create apk file

Sign apk file

launch emulator

install apk file

run instrumentalTest

Save the tests into an HTML Junit Report

Anyone know how to achieve this? so far my build file looks like this:..

<!-- WARNING: Eclipse auto-generated file.
              Any modifications will be overwritten.
              To include a user specific buildfile here, simply 

create one in the same
              directory with the processing instruction <?

eclipse.ant.import?>
              as the first entry and export the buildfile again. 

-->
<project basedir="." default="build" name="Unity Agent SDK Test">
 <property environment="env" />
 <property name="junit.output.dir" value="junit" />
 <property name="debuglevel" value="source,lines,vars" />
 <property name="target" value="1.6" />
 <property name="source" value="1.6" />
 <property file="build.properties" />
 <path id="android1.6.userclasspath">
  <pathelement location="lib/android.jar" />
 </path>
 <path id="Junit.userclasspath">
  <pathelement location="lib/junit-4.8.2" />
  <pathelement location="lib/org.hamcrest.core_1.1.0.v20090501071000.jar" />
 </path>
 <path id="Unity Agent SDK Test.classpath">
  <pathelement location="bin" />
  <pathelement location="lib/fb_connect-android-api.jar" />
  <pathelement location="lib/signpost-commonshttp4-1.2.jar" />
  <pathelement location="lib/signpost-core-1.2.jar" />
  <pathelement location="lib/UnityAgentSDK.jar" />
  <path refid="android1.6.userclasspath" />
  <path refid="Junit.userclasspath" />
 </path>

 <path id="android.antlibs">
  <pathelement path="${android-sdk-path}/tools/lib/anttasks.jar" />
  <pathelement path="${android-sdk-path}/tools/lib/sdklib.jar" />
  <pathelement path="${android-sdk-path}/tools/lib/androidprefs.jar" />
  <pathelement path="${android-sdk-path}/tools/lib/apkbuilder.jar" />
  <pathelement path="${android-sdk-path}/tools/lib/jarutils.jar" />
 </path>

 <path id="run.Unity Agent SDK Test (1).classpath">
  <path refid="Unity Agent SDK Test.classpath" />
 </path>
 <path id="run.Unity Agent SDK Test (1).bootclasspath" />
 <target name="init">
  <echo message="Initialize project" />
  <mkdir dir="bin" />
  <copy includeemptydirs="false" todir="bin">
   <fileset dir="src">
    <exclude name="**/*.launch" />
    <exclude name="**/*.java" />
   </fileset>
  </copy>
  <copy includeemptydirs="false" todir="bin">
   <fileset dir="gen">
    <exclude name="**/*.launch" />
    <exclude name="**/*.java" />
   </fileset>
  </copy>
 </target>

 <target name="clean">
  <echo message="Cleaning project" />
  <delete dir="bin" />
 </target>
 <target depends="clean" name="cleanall" />
 <target depends="build-subprojects,build-project" name="build" />
 <target name="build-subprojects" />
 <target depends="init" name="build-project">
  <echo message="${ant.project.name}: ${ant.file}" />
  <javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
   <src path="src" />
   <classpath refid="Unity Agent SDK Test.classpath" />
  </javac>
  <javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
   <src path="gen" />
   <classpath refid="Unity Agent SDK Test.classpath" />
  </javac>
 </target>
 <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects" />
 <target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
  <copy todir="${ant.library.dir}">
   <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar" />
  </copy>
  <unzip dest="${ant.library.dir}">
   <patternset includes="jdtCompilerAdapter.jar" />
   <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar" />
  </unzip>
 </target>
 <target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
  <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" />
  <antcall target="build" />
 </target>
 <target name="Unity Agent SDK Test ">
  <mkdir dir="${junit.output.dir}" />
  <echo message="making directory" />
  <junit fork="yes" printsummary="yes">
   <formatter type="xml" />
   <test name="com.kc.AllTests" todir="${junit.output.dir}" />

   <!--
   <test name="com.kc.AllTests" todir="${junit.output.dir}" />

             <test name="com.kc.unity.agent.util.ActivityOneTestcase" todir="${junit.output.dir}" />
   <test name="com.kc.unity.agent.util.FaceBookRestManagerTestCase" todir="${junit.output.dir}" />
   <test name="com.kc.unity.agent.util.OAuthManagerTestCase" todir="${junit.output.dir}" /> 
-->

   <classpath refid="Unity Agent SDK Test.classpath" />

   <bootclasspath>
    <path refid="run.Unity Agent SDK Test (1).bootclasspath" />
   </bootclasspath>
  </junit>
  <echo message="junit finished" />
 </target>
 <target name="junitreport">
  <junitreport todir="${junit.output.dir}">
   <fileset dir="${junit.output.dir}">
    <include name="TEST-*.xml" />
   </fileset>
   <report format="frames" todir="${junit.output.dir}" />
  </junitreport>
 </target>

 <!--
 Build it and set it up for android
 -->
 <echo message="Build it and set it up for android" />
  <echo message="${android-sdk-path}" />
  <target name="push_tests_to_device"  depends="build">
   <exec executable="${android-sdk-path}/tools/adb.exe">
    <arg value="install"/>
    <arg value="${test_apk_path}"/>
   </exec>
  </target>

  <target name="run_tests"  depends="push_tests_to_device">
   <exec executable="${android-sdk-path}/tools/adb.exe">
    <arg value="shell"/>
    <arg value="am"/>
    <arg value="instrument"/>
    <arg value="-w"/>
    <arg value="com.kc.tests/android.test.InstrumentationTestRunner"/>
   </exec>
  </target>

</project>

i can clean and build the project fine but dont know how to create the apk file, sign it, run the instrumentalTest and produce junit reports in html.

thanks in advance. this is the first time i have dived into this. i tried auto generating the build.xml using eclipse > project > export >ant build script and it doesnt add the apk building, running the instrumenatlTest and running the emulator stuff in it.