Android的摇篮应用程序:connectedCheck往返依赖性测试 [英] Android Gradle app:connectedCheck runs tests from dependencies

查看:707
本文介绍了Android的摇篮应用程序:connectedCheck往返依赖性测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些库项目,有它自己的测试。我不负责这个库项目,并不在乎它的测试,但是,当我运行摇篮:应用:connectedCheck 运行我的测试,但它也运行依赖的测试。有没有什么办法可以prevent呢?

我要指出,我的依赖是不是应用程序中模块I可言。

编辑:更具体地说,库项目中,我根据有,因为他们是为了在凌晨2时生成服务器上运行极长时间的测试,所以我坐在这里等着漆干刚跑我真的很短的测试。

EDIT2:我用勺子也试过。我把它设置,现在,可以运行单独的类,但我想在一个封装中运行的一切。这可能吗?

EDIT3:该文件夹结构是微不足道的,但这里是一个非常非常不详细介绍:

 根
-some_library_project
-main_project
-settings.gradle
 

在main_project build.gradle看起来是这样的。我应该指出,勺子目前正在做什么,但我的选择是开放的:

  buildscript {
 库{
     jcenter()
 }
 依赖{
     类路径com.stanfy.spoon:勺子摇篮 - 插件:0.10 +。
 }
}

应用插件:com.android.application
应用插件:'勺子'

安卓{
    compileSdkVersion 20
    buildToolsVersion '20 .0.0

 defaultConfig {
    的applicationIDcom.something.main_project
    的minSdkVersion 17
    targetSdkVersion 20
    版本code 1
    VERSIONNAME1.0

    testPackageNamecom.something.main_project.test
    testInstrumentationRunnerandroid.test.InstrumentationTestRunner

 }

 signingConfigs {
    调试{
        storeFile文件(debug.keystore)
    }

    推出 {
        storeFile文件(release.keystore)
        storePassword东西
        keyAlias​​东西
        keyPassword东西
    }
 }

 buildTypes {
    推出 {
        runProguard假
        proguardFiles getDefaultProguardFile('ProGuard的-android.txt'),'proguard-rules.pro
        signingConfig signingConfigs.release
    }
    调试{
        signingConfig signingConfigs.debug
    }
 }

}

依赖{
    编译文件树(导演:库,包括:['的* .jar'])

    编制项目(:some_library_project)

    androidTestCompilecom.squareup.spoon:勺子客户端:1.1.0
}

勺 {
    如果(project.hasProperty('spoonClassName')){
        的className = project.spoonClassName
    }
}
 

解决方案

您有勺子的插件,但与运行摇篮:应用程序:connectedCheck 。首先,这些变化,然后用摇篮勺子

运行

注释掉 androidTest.setRoot 其他任何build.gradle其他主包

这些加入 build.gradle 主包的:

在标记机器人

  sourceSets {//这一次可能没有必要。但不会伤害。
    androidTest.setRoot(SRC / androidTest)
}
 

修改勺子标签:

 勺{
     调试=真
     testSizes = ['小','中','大']<< ---改变这种运行特定的测试规模
     如果(project.hasProperty('spoonClassName')){
        的className = project.spoonClassName
     }
  }
 


运行

所有的测试:

  

摇篮勺子

具体测试类

  

摇篮勺-PspoonClassName = [THE.PACKAGE.NAME]


修改

阅读您的编辑EDIT2后,我看到这只会指定一个特定的类来运行,而不是一个特定的软件包。不幸的是,我还没有找到一个解决的办法,只有一个变通。我建了一个bash脚本,并在其中我加我的课测试,像这样:

第1步:在你的Andr​​oid项目的根目录下创建一个文件: runAllTests.sh

第二步:修改 .SH 来是这样的:

 #!/ bin / sh的
 日期+%B-%胸苷%H.%M> timestamp.out

 网站=$ HOME/路径/到/项目/根

 时间戳=$(猫$站点/timestamp.out)
 result_folder =$站点/结果
 DESTDIR =$ result_folder /结果$时间戳

 MKDIR -p$ DESTDIR
 回声目录中创建:$ {DESTDIR ## * /}

  < ----------在这里,你开始运行测试--------------->

  回声启动主安装程序
  摇篮勺子-PspoonClassName = com.es presso.test.MasterSetup
  CP -r$站点/程序/编译/勺子$ DESTDIR/主导安装
  回声结果保存到主导安装

  回声启动WorkoutSchedule
  摇篮勺子-PspoonClassName = com.es presso.test.CupcakeSchedule
  CP -f$站点/程序/编译/勺子$ DESTDIR/ WorkoutSchedule
  回声结果保存到WorkoutSchedule

  回声启动Setting.test
  摇篮勺子-PspoonClassName = com.es presso.test.Settings
  CP -r$站点/程序/编译/勺子$ DESTDIR/设置
  回声结果保存设置
 

第三步:给脚本的权限

  1. 光盘到脚本
  2. 键入 CHMODü+ X runAllTest.sh

那么,这是什么一样:

  1. 首先,它会创建一个timestamp.out。我用这个,所以我可以一遍又一遍我的结果保存到文件中没有previous结果被覆盖。你并不需要这一部分。

  2. 接下来,它会在你的项目的根一个结果文件夹,如果它已不存在。

  3. 那么,就会使结果文件夹命名为结果 - 有些-DATE中的文件夹。

  4. 最后,每个测试运行,结果保存到您的项目在正常的位置。 (内搭/汤匙)一旦测试完成后,将结果复制到结果文件夹,所以很容易看到你所有的测试运行适当命名每个测试结果。

注意:这个脚本是MAC地址写的。如果您在Windows或其他任何东西,这个脚本可能需要修改。


此外:您会发现这是很不方便的打开每个文件夹来获取 index.html的打开。所以我写了这个脚本添加到您的的.bash_profile

 函数open-结果(){
#浏览器打开了'的index.html'研究。
浏览器='/应用/谷歌Chrome.app /内容/ MacOS的/谷歌浏览器

#让用户知道,我们正在寻找在哪个目录
printf的看在%s$(PWD)
回声 ...

在$路径(找到./ -name调试型D);做
  对于文件中的$(发现$路径-name'的index.html');做
    开放-a$浏览器$文件
  做完
做完
回声完成
}
 

现在,cd到结果 - 有些-DATE ,然后键入开放式结果再次,这是对于bash写的。您可能需要根据您的操作系统进行修改。但结构应该是相同的

我希望这有助于。

I have some library project that has its own tests. I'm not responsible for this library project and don't care about its tests, however, when I run gradle :app:connectedCheck it runs my tests but it also runs the dependencies' tests. Is there any way I can prevent this?

I should mention that my dependencies are not within the app module I speak of.

EDIT: More specifically, the library project I'm depending on has extremely long tests as they are meant to run on a build server at 2 in the morning, so I'm sitting here waiting for paint to dry just to run my really short tests.

EDIT2: I've also tried using Spoon. I have it setup right now and can run individual classes, but I'd like to run everything in one package. Is that possible?

EDIT3: The folder structure is insignificant but here's a very very non-detailed look:

root
-some_library_project
-main_project
-settings.gradle

The main_project build.gradle looks like this. I should mention that spoon is currently doing nothing, but my options are open:

buildscript{
 repositories {
     jcenter()
 }
 dependencies{
     classpath 'com.stanfy.spoon:spoon-gradle-plugin:0.10.+'
 }
}

apply plugin: 'com.android.application'
apply plugin: 'spoon'

android {
    compileSdkVersion 20
    buildToolsVersion '20.0.0'

 defaultConfig {
    applicationId "com.something.main_project"
    minSdkVersion 17
    targetSdkVersion 20
    versionCode 1
    versionName "1.0"

    testPackageName "com.something.main_project.test"
    testInstrumentationRunner "android.test.InstrumentationTestRunner"

 }

 signingConfigs {
    debug {
        storeFile file("debug.keystore")
    }

    release {
        storeFile file("release.keystore")
        storePassword "something"
        keyAlias "something"
        keyPassword "something"
    }
 }

 buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
    }
    debug{
        signingConfig signingConfigs.debug
    }
 }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile project(':some_library_project')

    androidTestCompile 'com.squareup.spoon:spoon-client:1.1.0'
}

spoon {
    if (project.hasProperty('spoonClassName')){
        className = project.spoonClassName
    }
}

解决方案

You have the Spoon plugin, but are running with gradle :app:connectedCheck. First, make these changes, then run with gradle spoon

Comment out androidTest.setRoot any other build.gradle other that the main package

Add these to build.gradle of the main package:

Under tag android

sourceSets {  //this one may not be needed. But wont hurt.
    androidTest.setRoot('src/androidTest')
}

Modify spoon tag:

 spoon {
     debug = true
     testSizes = ['small', 'medium', 'large']   <<--- Change this to run specific test sizes
     if (project.hasProperty('spoonClassName')){
        className = project.spoonClassName
     }
  }


To run

All tests:

gradle spoon

Specific Test Class

gradle spoon -PspoonClassName=[THE.PACKAGE.NAME]


Edit

After reading your edit "Edit2", I see that this will only specify a certain class to run, and not a specific package. Unfortunately, I have not found a solution to this, only a work-around. I built a bash script and in it I added my classes to test, like so:

Step 1: Create a file at the root of your Android project: runAllTests.sh

Step 2: Edit .sh to look like this:

 #!/bin/sh
 date +%b-%dT%H.%M > timestamp.out

 sites="$HOME"/path/to/project/root

 timestamp="$(cat "$sites"/timestamp.out)"
 result_folder="$sites"/results
 destdir="$result_folder/Results-$timestamp"

 mkdir -p "$destdir"
 echo "Directory created: ${destdir##*/}"

  <---------- Here you start running the test --------------->

  echo "Starting Master Setup"
  gradle spoon -PspoonClassName=com.espresso.test.MasterSetup
  cp -r "$sites"/app/build/spoon "$destdir"/MasterSetup
  echo "Results saved to MasterSetup"

  echo "Starting WorkoutSchedule"
  gradle spoon -PspoonClassName=com.espresso.test.CupcakeSchedule
  cp -f "$sites"/app/build/spoon "$destdir"/WorkoutSchedule
  echo "Results saved to WorkoutSchedule"

  echo "Starting Setting.test"
  gradle spoon -PspoonClassName=com.espresso.test.Settings
  cp -r "$sites"/app/build/spoon "$destdir"/Settings
  echo "Results saved to Settings"

Step 3: Give the script permissions

  1. cd to the script
  2. type chmod u+x runAllTest.sh

So, what this does:

  1. First, it creates a timestamp.out. I use this so I can save my results to a file over and over without previous results being overwritten. You do not need this part.

  2. Next, it creates a result folder in the root of your project if it is not already there.

  3. Then, it will make a folder inside the results folder named Results-SOME-DATE.

  4. Lastly, each test will run, saving the results to the normal spot on your project. (Inside build/spoon) Once test are complete it will copy the results to the results folder, and name each test result appropriately so it is easy to see all your tests ran.

NOTE: This script was written for MAC. If your on windows or anything else, this script may need modifications.


Additionally: You will find it is inconvenient to open in to each folder to get the index.html opened. So I wrote this script to add to your bash_profile:

function open-results () {
# the browser to open up `index.html' in.
browser='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'

# let the user know what directory we're looking in
printf "looking in %s" "$(pwd)"
echo ...

for paths in $(find ./ -name 'debug' -type d); do
  for files in $(find "$paths" -name 'index.html'); do
    open -a "$browser" "$files"
  done
done
echo done
}

Now, cd to the Results-SOME-DATE, and type open-results. Again, this was written for bash. You may need to modify depending on your OS. But the structure should be the same

I hope this helps.

这篇关于Android的摇篮应用程序:connectedCheck往返依赖性测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆