Android studio(仪器仪表)的Gradle测试

时间:2013-12-10 19:30:42

标签: android gradle android-studio instrumentation

我目前在android平台上编写了一个应用程序,我决定使用gradle。对我来说不幸的是,那些对maven有经验并且只有小蚂蚁,gradle的人似乎不是我的盟友。

我已经从stackoverflow上的其他帖子复制了test {}代码段,但它对我不起作用。

Mine gradle文件:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.3+'
    }
}



apply plugin: 'android'

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

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')
        instrumentTest {
           java.srcDirs = ['tests/src']
           res.srcDirs = ['tests/res']
           assets.srcDirs = ['tests/assets']
           resources.srcDirs = ['tests/src']
        }        

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')




    }
}




test {
  //makes the standard streams (err and out) visible at console when running tests
  testLogging.showStandardStreams = true
}

失败并出现这样的错误

tomasz@tomasz-K50IN:MediaPlayer$ ../gradlew connectedInstrumentTest --info
    Starting Build
    Starting file lock listener thread.
    Settings evaluated using settings file '/home/tomasz/Dokumenty/prace/uczelnia/inzynierka/inzynierkateam/private/mediaplayer/settings.gradle'.
    Projects loaded. Root project using build file '/home/tomasz/Dokumenty/prace/uczelnia/inzynierka/inzynierkateam/private/mediaplayer/build.gradle'.
    Included projects: [root project 'mediaplayer', project ':MediaPlayer']
    Evaluating root project 'mediaplayer' using build file '/home/tomasz/Dokumenty/prace/uczelnia/inzynierka/inzynierkateam/private/mediaplayer/build.gradle'.
    Evaluating project ':MediaPlayer' using build file '/home/tomasz/Dokumenty/prace/uczelnia/inzynierka/inzynierkateam/private/mediaplayer/MediaPlayer/build.gradle'.

    FAILURE: Build failed with an exception.

    * Where:
    Build file '/home/tomasz/Dokumenty/prace/uczelnia/inzynierka/inzynierkateam/private/mediaplayer/MediaPlayer/build.gradle' line: 60

    * What went wrong:
    A problem occurred evaluating project ':MediaPlayer'.
    > Could not find method test() for arguments [build_2pl8ohuuj2k1m4ub1d62lfkgmg$_run_closure3@c3c727] on project ':MediaPlayer'.

    * Try:
    Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

    BUILD FAILED

    Total time: 9.2 secs

当扔掉测试{..}时,似乎成功通过了所有测试,但它没有正确运行测试。我添加到我的测试断言(1 == 0) - 它应该失败,但不会失败。

我做错了什么?可以方便地在android-studio中运行gradle instrumentation测试,因为intellij idea项目中的常规测试(gui显示堆栈跟踪错误)或netbeans maven测试不仅仅是命令式?

我的项目结构:

.
├── build.gradle
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── local.properties
├── MediaPlayer
│   ├── AndroidManifest.xml
│   ├── build.gradle
│   ├── CHANGELOG
│   ├── ic_launcher-web.png
│   ├── libs
│   │   ├── android-query.0.26.7.jar
│   │   ├── android-support-v4.jar
│   │   ├── eventbus-2.1.0-beta-1.jar
│   │   ├── guice-3.0-no_aop.jar
│   │   ├── javax.inject.jar
│   │   ├── jsr305-1.3.9.jar
│   │   └── roboguice-2.0.jar
│   ├── lint.xml
│   ├── local.properties
│   ├── MediaPlayer.iml
│   ├── proguard-project.txt
│   ├── project.properties
│   ├── res
│   │   ├── drawable
│   │   │   ├── cd.png
│   │   │   ├── ic_launcher.png
│   │   │   ├── next.png
│   │   │   ├── nuta.png
│   │   │   ├── pause.png
│   │   │   ├── playlist_icon.png
│   │   │   ├── play.png
│   │   │   ├── prev.png
│   │   │   ├── repeat.png
│   │   │   ├── shuffle.png
│   │   │   └── track_icon.png
│   │   ├── drawable-hdpi
│   │   │   └── ic_launcher.png
│   │   ├── drawable-mdpi
│   │   │   └── ic_launcher.png
│   │   ├── drawable-xhdpi
│   │   │   └── ic_launcher.png
│   │   ├── drawable-xxhdpi
│   │   │   └── ic_launcher.png
│   │   ├── layout
│   │   │   ├── activity_media_manager_demo.xml
│   │   │   ├── activity_searcher.xml
│   │   │   ├── notification_player_layout.xml
│   │   │   ├── player_activity.xml
│   │   │   ├── sa_result_view_album_item.xml
│   │   │   ├── sa_result_view_playlist_item.xml
│   │   │   └── sa_result_view_track_item.xml
│   │   ├── menu
│   │   │   └── player.xml
│   │   ├── values
│   │   │   ├── dimens.xml
│   │   │   ├── strings.xml
│   │   │   └── styles.xml
│   │   ├── values-sw600dp
│   │   │   └── dimens.xml
│   │   ├── values-sw720dp-land
│   │   │   └── dimens.xml
│   │   ├── values-v11
│   │   │   └── styles.xml
│   │   └── values-v14
│   │       └── styles.xml
│   ├── src
│   │   └── pl
│   │       └── pw
│   │           ├── mini
│   │           │   └── mediaplayer
│   │           │       ├── Constans.java
│   │           │       ├── Events.java
│   │           │       └── utilities
│   │           │           ├── LogUtils.java
│   │           │           └── Utility.java
│   │           └── ppo
│   │               └── MediaPlayer
│   │                   ├── Events.java
│   │                   ├── Model
│   │                   │   ├── Album.java
│   │                   │   ├── AudioRecord.java
│   │                   │   ├── Playlist.java
│   │                   │   └── Track.java
│   │                   ├── MusicManager
│   │                   │   ├── Albums.java
│   │                   │   ├── MusicDbManager.java
│   │                   │   ├── MusicManagerInterface.java
│   │                   │   ├── Playlists.java
│   │                   │   └── Tracks.java
│   │                   ├── Player
│   │                   │   ├── Activities
│   │                   │   │   ├── PlayerActivityCommand.java
│   │                   │   │   ├── PlayerActivity.java
│   │                   │   │   ├── PlayerStatus.java
│   │                   │   │   └── TrackInfo.java
│   │                   │   ├── Events.java
│   │                   │   └── Services
│   │                   │       ├── LoopMode.java
│   │                   │       ├── LoopModePlayerServiceCommand.java
│   │                   │       ├── PlayerAction.java
│   │                   │       ├── PlayerBackgroundService.java
│   │                   │       ├── PlayerServiceCommand.java
│   │                   │       ├── PlayerState.java
│   │                   │       ├── ShuffleMode.java
│   │                   │       ├── ShuffleModePlayerServiceCommand.java
│   │                   │       └── TrackInfo.java
│   │                   ├── Searcher
│   │                   │   ├── SearcherActivity.java
│   │                   │   └── SearcherResultAdapter.java
│   │                   └── Trash
│   │                       └── MediaManagerDemo.java
│   └── tests
│       └── java
    |            |__pl
│              └── pw
│                 └── ppo
│                     └── MediaPlayer
│                        └── Player
│                           └── Activities
│                               ├── PlayerActivityTest.java
│                               └── PlayerBackgroundServiceTest.java
├── mediaplayer.iml
└── settings.gradle

39 directories, 87 files

1 个答案:

答案 0 :(得分:4)

测试任务可能被称为test以外的其他任务。 (您可以使用gradle tasks --all列出所有可用任务。)此外,测试目录似乎未正确配置(我在目录树中看不到tests/src)。