2012-03-14 33 views
6

Sürekli bir yapı ortamında Robolectric'i kurmak için çalışıyorum ve herşeyi ayarlıyorum.Robolectric ve ANT ile test etme

Benim android Eclipse proje yapısı, bir Android projesi ve Robolectric “Hızlı Başlangıç ​​for Eclipse” hızlı kılavuzunda açıklandığı gibi bir JUnit4 test projesinden oluşur. Örnek testlerim Eclipse'in içinden gayet iyi çalışıyor, ama karınca ile de test yapabilmem gerekiyor. Bunu desteklemek için ANT build.xml'imi nasıl kurabilirim? ve Eclipse test projesinde yapılan aynı değişiklikleri nasıl uygulamalıyım?

RobolectricSample projesinin build.xml dosyasına bakıyordum, ancak proje src klasörü altında bulunan hem üretim hem de test koduna sahip tek bir projeden oluşuyor. Anladığım kadarıyla, maven işlerin nasıl olduğunu varsayar (???), fakat sadece ANT için gitmek istiyorum.

+0

henüz bu anlamaya mi? Benzer durumdayım, ANT kullanarak inşa etmek istiyorum. – bianca

cevap

4

Bu eskidir ama umarım bu başka birine yardımcı olur. Bunu son zamanlarda yaptım ... robolectric, mockito, Jenkins ve karınca. İşte koştum karınca inşa komut dosyası. Temel olarak sadece kütüphanelerinize giden yolu ayarlamanız ve testi başlatmak için bir hedef belirlemeniz yeterlidir. Ben de android.jar dosyasını ve maps.jar dosyasını test projesinin lib klasörüne kopyalarım, bu da hayatı kolaylaştırıyor gibi görünüyor ama belki de bunu daha iyi bir şekilde yapabilirsiniz.

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<project name="unit_tests" default="test-report-junit" basedir="."> 
<description> 
    Sample Robolectric Ant Build 
</description> 

<!-- set global properties for this build, if you have libraries, include them here with a relative path...I have samples as library1, library2, library3, located on the same level as your project, but you may need to modified this to get it to work for your setup. --> 

<property name="libs.dir" value="./lib/"/> 
<property name="build.dir" value="./build/"/> 
<property name="android.library1.classpath" value="./../../library1/bin/classes/"/> 
<property name="android.library2.classpath" value="./../../library2/bin/classes/"/> 
<property name="android.library3.classpath" value="./../../library3/bin/classes/"/>  
<property name="test.report.dir" value="./test-reports/"/> 
<property name="test.html.dir" value="./test-report-html/"/> 
<property name="source.dir" value="./src/"/>  

<filelist id="android_jars" dir="${libs.dir}"> 
    <file name="android.jar"/> 
    <file name="maps.jar"/> 
</filelist> 

<filelist id="libs_jars" dir="${libs.dir}"> 
    <file name="junit.jar"/> 
    <file name="hamcrest.jar"/> 
    <file name="json.jar"/> 
    <file name="google-play-services.jar"/> 
    <file name="mockito-all-1.9.5.jar"/> 
    <file name="robolectric-1.1-jar-with-dependencies.jar"/> 
</filelist> 

<path id="compile_classpath"> 
    <filelist refid="libs_jars"/> 
    <filelist refid="android_jars"/> 
    <pathelement path="${android.project.classpath}"/> 
    <pathelement path="${android.library1.classpath}"/> 
    <pathelement path="${android.library2.classpath}"/> 
    <pathelement path="${android.library3.classpath}"/> 
    <pathelement path="${build.dir}"/> 
</path> 

<path id="junit_classpath"> 
    <pathelement path="${build.dir}"/> 
    <pathelement path="${android.library1.classpath}"/> 
    <pathelement path="${android.library2.classpath}"/> 
    <pathelement path="${android.library3.classpath}"/> 

    <!-- NOTE: junit.jar must come before android.jar! --> 
    <filelist refid="libs_jars"/> 
    <filelist refid="android_jars"/> 
</path> 

<!-- targets --> 

<target name="init"> 
    <!-- Create the time stamp --> 
    <tstamp/> 
    <mkdir dir="${build.dir}"/> 
</target> 

<target name="compile" depends="init" description="compile test source"> 
    <javac srcdir="${source.dir}" destdir="${build.dir}" debug="true" > 
     <classpath refid="compile_classpath" /> 
    </javac> 

    <copy todir="build"> 
     <fileset dir="src" includes="**/*.xml,**/*.properties,**/*.txt,**/*.ico" /> 
    </copy> 
</target> 

<target name="test-run" depends="compile" description="Run JUnit tests"> 
    <mkdir dir="${test.report.dir}"/> 
    <echo message="Running JUnit Tests in directory ${source.dir}..."/> 
    <junit showoutput="true" printsummary="yes" failureproperty="junit.failure" fork="yes" forkmode="once" maxmemory="512m"> 
     <formatter type="plain"/> 
     <formatter type="xml"/> 
     <batchtest todir="${test.report.dir}"> 
      <fileset dir="${source.dir}"> 
       <include name="**/*Test.java"/> 
      </fileset> 
     </batchtest> 
     <classpath refid="junit_classpath"/> 
    </junit> 
    <fail if="junit.failure" message="Unit test(s) failed. See reports!"/> 
</target> 

<target name="test-report-junit" depends="test-run" description="Generate JUnit HTML reports"> 
    <mkdir dir="${test.html.dir}"/> 
    <junitreport todir="${test.report.dir}"> 
     <fileset dir="${test.report.dir}" includes="TEST-*.xml"/> 
     <report format="frames" todir="${test.html.dir}"/> 
    </junitreport> 
</target> 

<target name="clean" description="Clean Up" > 
    <delete dir="${build.dir}"/> 
    <delete dir="${test.report.dir}"/> 
    <delete dir="${test.html.dir}"/> 
    <delete file="${basedir}/tmp/cached-robolectric-classes.jar"/> 
</target> 
</project> 

Son olarak, tüm başlamak için Jenkins aşağıdaki komutu çalıştırın:

ant -f ./build-ant.xml test-report-junit 
+0

Neden "test-report-junit" argümanını sağlamanız gerekiyor? –