2012-12-17 72 views

回答

2

您可以使用adb shell "start instrument -w -e class package_name/class_name package_name/android.test.InstrumentationTestRunner"

+0

我把它包裝到一個自定義目標中。謝謝! –

0

我創造了我自己的目標custom_rules.xml抽象一點從user674199的回答是:

<target name="test-single" depends="-test-project-check" description="Runs a single test case, given with -DclassToTest=package.path.to.Class"> 
    <run-tests-helper> 
     <extra-instrument-args> 
      <arg value="-e" /> 
       <arg value="class" /> 
       <arg value="${classToTest}" /> 
     </extra-instrument-args> 
    </run-tests-helper> 
</target> 

,供應我的目的,相當不錯。

0

托馬斯的回答是有點過時,或只是不要因爲錯誤的工作:

testSingle: 
    [echo] Running tests ... 
    [exec] /system/bin/sh: ${test.runner}: bad substitution 

如果你看到原來test目標在Android SDK中build.xml你看到一些其他所需的屬性之前設置,所以這裏是一個對於我的工作目標:

<!-- custom test target to perform specific test only --> 
<target 
    name="testSingle" 
    depends="-test-project-check" 
    description="Runs a single test case, given with -DtestClass=package.path.to.Class"> 

    <property name="test.runner" value="android.test.InstrumentationTestRunner" /> 
    <property name="tested.project.absolute.dir" location="${tested.project.dir}" /> 

    <!-- Application package of the tested project extracted from its manifest file --> 
    <xpath input="${tested.project.absolute.dir}/AndroidManifest.xml" 
      expression="/manifest/@package" output="tested.project.app.package" /> 

    <run-tests-helper> 
     <extra-instrument-args> 
      <arg value="-e" /> 
      <arg value="class" /> 
       <arg value="${testClass}" /> 
     </extra-instrument-args> 
    </run-tests-helper> 
</target> 

這是我如何運行它:

ant instrument testSingle -DtestClass=com.company.tests.SomeTest

其中com.company.tests.SomeTest是完整的測試類名稱。

相關問題