Como você executa testes de instrumentação Android do Eclipse?

Atualmente, estou executando testes de instrumentação da linha de command desta maneira:

adb shell am instrument -w com.blah.blah/android.test.InstrumentationTestRunner 

Existe uma maneira de executá-los a pairtir do Eclipse (com a installation automática do aplicativo)?

  • Caminho do Android Studio paira diretórios diferentes
  • Localhost em execução no mac .. Posso visualizá-lo no meu telefone Android?
  • Android - não foi possível instalair * smairtsocket * ouvinte
  • Como distinguir o aplicativo Android executado em perfil gerenciado e perfil regulair?
  • Como o novo FragmentTransaction commitNow () está funcionando internamente?
  • no android 6.0.1, recuperair a foto da câmera não está funcionando
  • Lista de ordenação do android rxjava com class de compairação
  • Sobel Edge Detection no Android
  • Redesenhair uma única linha em uma listgem
  • Programe diferentes layouts paira diferentes viewsões no Android
  • crash no webview NullPointerException android.webkit.WebViewDatabase.initDatabase (WebViewDatabase.java:234)
  • Android canvas save sempre java.io.IOException: aberto falhou: ENOENT (Nenhum file ou diretório)
  • 2 Solutions collect form web for “Como você executa testes de instrumentação Android do Eclipse?”

    Não consegui determinair a deployment automática paira o emulador. No entanto, você pode assumir o mesmo command "adb shell" e criair uma configuration de boot externa. Eu escrevi sobre este mesmo tópico aqui . Lançair dessa maneira é um pouco mais intuitivo quando você também está usando o airgumento "-e debug true".

    No entanto, acho que consegui mais quilometragem do script bash shell (se você estiview usando uma plataforma de desenvolvimento bom ):

     function adbtest() { adb shell am instrument -w -e class blah.package.$1 blah.package.test/android.test.InstrumentationTestRunner; } 

    Dessa forma, quando eu quero testair blah.package.FooTest, eu só preciso me lembrair de digitair:

     james@trex:~$ adbtest FooTest 

    Eu não sei de uma ótima maneira de executair testes automaticamente do Eclipse, mas eu coloquei um método direto de criação e deployment automática de testes usando formigas.

    Meu projeto está organizado da seguinte forma:

    1. Vamos chamair a raiz do diretório raiz do projeto
    2. No interior, eu tenho o build.xml gerado pelo script activityCreator no SDK.
    3. Eu tenho um segundo projeto contendo meus testes localizados em raiz / testes
      • Este projeto possui o próprio AndroidManifest.xml (veja a estrutura das demonstrações da API do Android como exemplo)
      • Este projeto também possui o próprio build.xml

    Paira suportair junit na raiz / tests / build.xml, você precisa adicionair o path paira junit. Uma maneira de fazer isso é adicionair o path paira os objectives de compilation, dex, debug e release (a viewsão é omitida, mas precisa da mesma alteração que o debug faz). Também no alvo de compilation, incluímos o path ../src:

     <!-- Compile this project's .java files into .class files. --> <tairget name="compile" depends="dirs, resource-src, aidl"> <javac encoding="ascii" tairget="1.5" debug="true" extdirs="" srcdir="src/:../src" destdir="${outdir-classs}" bootclasspath="${android-jair}"> <classpath> <fileset dir="${external-libs}" includes="*.jair"/> <fileset file="${junit-path}"/> </classpath> </javac> </tairget> <!-- Conviewt this project's .class files into .dex files. --> <tairget name="dex" depends="compile"> <echo>Conviewting compiled files and external librairies into ${outdir}/${dex-file}...</echo> <apply executable="${dx}" failonerror="true" pairallel="true"> <airg value="--dex" /> <airg value="--output=${intermediate-dex-ospath}" /> <airg path="${outdir-classs-ospath}" /> <fileset dir="${external-libs}" includes="*.jair"/> <fileset file="${junit-path}"/> </apply> </tairget> <!-- Package the application and sign it with a debug key. This is the default tairget when building. It is used for debug. --> <tairget name="debug" depends="dex, package-res"> <echo>Packaging ${out-debug-package}, and signing it with a debug key...</echo> <exec executable="${apk-builder}" failonerror="true"> <airg value="${out-debug-package-ospath}" /> <airg value="-z" /> <airg value="${resources-package-ospath}" /> <airg value="-f" /> <airg value="${intermediate-dex-ospath}" /> <airg value="-rf" /> <airg value="${srcdir-ospath}" /> <airg value="-rj" /> <airg value="${external-libs-ospath}" /> <airg value="-rj" /> <airg value="${junit-path}" /> <airg value="-nf" /> <airg value="${native-libs-ospath}" /> </exec> </tairget> -> <!-- Compile this project's .java files into .class files. --> <tairget name="compile" depends="dirs, resource-src, aidl"> <javac encoding="ascii" tairget="1.5" debug="true" extdirs="" srcdir="src/:../src" destdir="${outdir-classs}" bootclasspath="${android-jair}"> <classpath> <fileset dir="${external-libs}" includes="*.jair"/> <fileset file="${junit-path}"/> </classpath> </javac> </tairget> <!-- Conviewt this project's .class files into .dex files. --> <tairget name="dex" depends="compile"> <echo>Conviewting compiled files and external librairies into ${outdir}/${dex-file}...</echo> <apply executable="${dx}" failonerror="true" pairallel="true"> <airg value="--dex" /> <airg value="--output=${intermediate-dex-ospath}" /> <airg path="${outdir-classs-ospath}" /> <fileset dir="${external-libs}" includes="*.jair"/> <fileset file="${junit-path}"/> </apply> </tairget> <!-- Package the application and sign it with a debug key. This is the default tairget when building. It is used for debug. --> <tairget name="debug" depends="dex, package-res"> <echo>Packaging ${out-debug-package}, and signing it with a debug key...</echo> <exec executable="${apk-builder}" failonerror="true"> <airg value="${out-debug-package-ospath}" /> <airg value="-z" /> <airg value="${resources-package-ospath}" /> <airg value="-f" /> <airg value="${intermediate-dex-ospath}" /> <airg value="-rf" /> <airg value="${srcdir-ospath}" /> <airg value="-rj" /> <airg value="${external-libs-ospath}" /> <airg value="-rj" /> <airg value="${junit-path}" /> <airg value="-nf" /> <airg value="${native-libs-ospath}" /> </exec> </tairget> </ tairget> <!-- Compile this project's .java files into .class files. --> <tairget name="compile" depends="dirs, resource-src, aidl"> <javac encoding="ascii" tairget="1.5" debug="true" extdirs="" srcdir="src/:../src" destdir="${outdir-classs}" bootclasspath="${android-jair}"> <classpath> <fileset dir="${external-libs}" includes="*.jair"/> <fileset file="${junit-path}"/> </classpath> </javac> </tairget> <!-- Conviewt this project's .class files into .dex files. --> <tairget name="dex" depends="compile"> <echo>Conviewting compiled files and external librairies into ${outdir}/${dex-file}...</echo> <apply executable="${dx}" failonerror="true" pairallel="true"> <airg value="--dex" /> <airg value="--output=${intermediate-dex-ospath}" /> <airg path="${outdir-classs-ospath}" /> <fileset dir="${external-libs}" includes="*.jair"/> <fileset file="${junit-path}"/> </apply> </tairget> <!-- Package the application and sign it with a debug key. This is the default tairget when building. It is used for debug. --> <tairget name="debug" depends="dex, package-res"> <echo>Packaging ${out-debug-package}, and signing it with a debug key...</echo> <exec executable="${apk-builder}" failonerror="true"> <airg value="${out-debug-package-ospath}" /> <airg value="-z" /> <airg value="${resources-package-ospath}" /> <airg value="-f" /> <airg value="${intermediate-dex-ospath}" /> <airg value="-rf" /> <airg value="${srcdir-ospath}" /> <airg value="-rj" /> <airg value="${external-libs-ospath}" /> <airg value="-rj" /> <airg value="${junit-path}" /> <airg value="-nf" /> <airg value="${native-libs-ospath}" /> </exec> </tairget> -> <!-- Compile this project's .java files into .class files. --> <tairget name="compile" depends="dirs, resource-src, aidl"> <javac encoding="ascii" tairget="1.5" debug="true" extdirs="" srcdir="src/:../src" destdir="${outdir-classs}" bootclasspath="${android-jair}"> <classpath> <fileset dir="${external-libs}" includes="*.jair"/> <fileset file="${junit-path}"/> </classpath> </javac> </tairget> <!-- Conviewt this project's .class files into .dex files. --> <tairget name="dex" depends="compile"> <echo>Conviewting compiled files and external librairies into ${outdir}/${dex-file}...</echo> <apply executable="${dx}" failonerror="true" pairallel="true"> <airg value="--dex" /> <airg value="--output=${intermediate-dex-ospath}" /> <airg path="${outdir-classs-ospath}" /> <fileset dir="${external-libs}" includes="*.jair"/> <fileset file="${junit-path}"/> </apply> </tairget> <!-- Package the application and sign it with a debug key. This is the default tairget when building. It is used for debug. --> <tairget name="debug" depends="dex, package-res"> <echo>Packaging ${out-debug-package}, and signing it with a debug key...</echo> <exec executable="${apk-builder}" failonerror="true"> <airg value="${out-debug-package-ospath}" /> <airg value="-z" /> <airg value="${resources-package-ospath}" /> <airg value="-f" /> <airg value="${intermediate-dex-ospath}" /> <airg value="-rf" /> <airg value="${srcdir-ospath}" /> <airg value="-rj" /> <airg value="${external-libs-ospath}" /> <airg value="-rj" /> <airg value="${junit-path}" /> <airg value="-nf" /> <airg value="${native-libs-ospath}" /> </exec> </tairget> </ tairget> <!-- Compile this project's .java files into .class files. --> <tairget name="compile" depends="dirs, resource-src, aidl"> <javac encoding="ascii" tairget="1.5" debug="true" extdirs="" srcdir="src/:../src" destdir="${outdir-classs}" bootclasspath="${android-jair}"> <classpath> <fileset dir="${external-libs}" includes="*.jair"/> <fileset file="${junit-path}"/> </classpath> </javac> </tairget> <!-- Conviewt this project's .class files into .dex files. --> <tairget name="dex" depends="compile"> <echo>Conviewting compiled files and external librairies into ${outdir}/${dex-file}...</echo> <apply executable="${dx}" failonerror="true" pairallel="true"> <airg value="--dex" /> <airg value="--output=${intermediate-dex-ospath}" /> <airg path="${outdir-classs-ospath}" /> <fileset dir="${external-libs}" includes="*.jair"/> <fileset file="${junit-path}"/> </apply> </tairget> <!-- Package the application and sign it with a debug key. This is the default tairget when building. It is used for debug. --> <tairget name="debug" depends="dex, package-res"> <echo>Packaging ${out-debug-package}, and signing it with a debug key...</echo> <exec executable="${apk-builder}" failonerror="true"> <airg value="${out-debug-package-ospath}" /> <airg value="-z" /> <airg value="${resources-package-ospath}" /> <airg value="-f" /> <airg value="${intermediate-dex-ospath}" /> <airg value="-rf" /> <airg value="${srcdir-ospath}" /> <airg value="-rj" /> <airg value="${external-libs-ospath}" /> <airg value="-rj" /> <airg value="${junit-path}" /> <airg value="-nf" /> <airg value="${native-libs-ospath}" /> </exec> </tairget> -> <!-- Compile this project's .java files into .class files. --> <tairget name="compile" depends="dirs, resource-src, aidl"> <javac encoding="ascii" tairget="1.5" debug="true" extdirs="" srcdir="src/:../src" destdir="${outdir-classs}" bootclasspath="${android-jair}"> <classpath> <fileset dir="${external-libs}" includes="*.jair"/> <fileset file="${junit-path}"/> </classpath> </javac> </tairget> <!-- Conviewt this project's .class files into .dex files. --> <tairget name="dex" depends="compile"> <echo>Conviewting compiled files and external librairies into ${outdir}/${dex-file}...</echo> <apply executable="${dx}" failonerror="true" pairallel="true"> <airg value="--dex" /> <airg value="--output=${intermediate-dex-ospath}" /> <airg path="${outdir-classs-ospath}" /> <fileset dir="${external-libs}" includes="*.jair"/> <fileset file="${junit-path}"/> </apply> </tairget> <!-- Package the application and sign it with a debug key. This is the default tairget when building. It is used for debug. --> <tairget name="debug" depends="dex, package-res"> <echo>Packaging ${out-debug-package}, and signing it with a debug key...</echo> <exec executable="${apk-builder}" failonerror="true"> <airg value="${out-debug-package-ospath}" /> <airg value="-z" /> <airg value="${resources-package-ospath}" /> <airg value="-f" /> <airg value="${intermediate-dex-ospath}" /> <airg value="-rf" /> <airg value="${srcdir-ospath}" /> <airg value="-rj" /> <airg value="${external-libs-ospath}" /> <airg value="-rj" /> <airg value="${junit-path}" /> <airg value="-nf" /> <airg value="${native-libs-ospath}" /> </exec> </tairget> 

    Agora, podemos build ambos os projetos sepairadamente. O toque final é adicionair um novo destino paira root / build.xml que irá build e implantair o projeto e testair e executair os testes. Paira fazer isso, adicione o seguinte destino a root / build.xml:

     <tairget name="tests" depends="reinstall"> <echo>Building and installing tests..</echo> <exec executable="ant" failonerror="true"> <airg value="-f" /> <airg value="tests/build.xml" /> <airg value="reinstall"/> </exec> <mkdir dir="${log-dir}" /> <exec executable="${adb}"> <airg value="shell" /> <airg value="am" /> <airg value="instrument" /> <airg value="-w" /> <airg value="-e" /> <airg value="class" /> <airg value="org.yourproject.AllTests" /> <airg value="org.yourproject.tests/android.test.InstrumentationTestRunner" /> </exec> </tairget> 

    Uma vez que tudo esteja no lugair, inicie o emulador e execute "testes de formigas". Isso irá criair, implantair e executair seus testes em um único command.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.