Reputation: 341
I currently write an application on the android platform and I have decided to use gradle. Unfortunately for me, person who has experience with maven and only little ant, gradle does not seem to be my ally.
I have copied test {} snippet from another post on the stackoverflow but it does not works for me.
Mine gradle file:
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
}
It fails with such a error
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
When throw away test { .. } it seems to be successfully pass all tests, but it does not run correctly tests. I added to mine test assert(1 == 0) - it should fail , but does not fail.
What am I doing wrongly? Can be gradle instrumentation tests run in android-studio conviniently as normal tests in intellij idea projects (gui shows errors with stacktraces) or netbeans maven tests not only command -like ?
My project structure:
.
├── 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
Upvotes: 4
Views: 3894
Reputation: 123958
The test task is likely called something other than test
. (You can list all available tasks with gradle tasks --all
.) Also, the test directory doesn't seem to be configured correctly (I don't see tests/src
in the directory tree).
Upvotes: 4