Giter Site home page Giter Site logo

android-gradle-template's Introduction

Android - Rapid Test Driven Development

  • Combine tools to generate most of the boilerplate code.
  • Examples how to test different aspects of an android application.
  • Clean architecture approach with MVP and package by feature.

For details see Project Documentations

Wishes, improvements, questions and discussions about the stuff here are welcome.

Circle CI Coverage Status

Last successful tests with

  • Android Studio 1.3.2
  • Gradle Build Tools 1.3.0
  • Gradle 2.6
  • Android v22
  • Java 8

Getting Started

Import the project into Android Studio and start developing. For more details see Getting Started

android-gradle-template's People

Contributors

bluehallu avatar ligi avatar nenick avatar richardguion avatar zsoltk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-gradle-template's Issues

run-tests.sh needs a simple fix

Scripts/run-tests.sh still refers to :AppUnitTests but should instead use :App as the unit tests were moved there. :)

Tom

A problem occurred evaluating project ':ComponentTestsRobolectric'

Hey there,

Thanks a lot for sharing. Recently I've upgraded my Android Studio to the latest version (0.8.2) and today I've noticed your project on github. Unfortunately tests don't pass when I run them from script and I am given this error:

A problem occurred evaluating project ':ComponentTestsRobolectric'.

(class: com/novoda/gradle/test/SupportedLanguages, method: super$1$stream signature: ()Ljava/util/stream/Stream;) Illegal use of nonvirtual function call.

Particularily, it complains in this line:

android {
projectUnderTest ':AndroidSample'
}

Primarily I thought it was connected with java version but it's not.

Is this the Android Studio version issue? Is anyone familiar with this error? If so, how to get it working?

Thanks,
Dawid

Maybe switch to JCAndKSolutions/android-unit-test

The mentioned plugin could replace the novoda/gradle-android-test-plugin.

Main reasons would be smarter integration into android studio and on going improvements. Novoda looks dead.

I see only one reason to stay on novoda version. That's the different kinds of testing (unit & integration). Both could be done with robolectric.

Unable to import project

  1. fresh clone
  2. I click "Import Project..." from the "Welcome to Android Studio" window.
  3. Select the build.gradle on the root folder
  4. I get the following error
    Error:(17, 0) (class: com/novoda/gradle/test/SupportedLanguages, method: super$1$stream signature: ()Ljava/util/stream/Stream;) Illegal use of nonvirtual function call

I am not sure if I'm missing something, I also tried

  1. fresh clone
  2. I ran Script/install-custom-gradle-test-plugin.sh from android-gradle-template folder
  3. I click "Import Project..." from the "Welcome to Android Studio" window.
  4. Select the build.gradle on the root folder
  5. I get the same error

I also tried

  1. fresh clone
  2. I ran install-custom-gradle-test-plugin.sh from android-gradle-template/Script folder
  3. I click "Import Project..." from the "Welcome to Android Studio" window.
  4. Select the build.gradle on the root folder
  5. I get the same error

Illegal use of nonvirtual function call

Received this when cloning the project today.

$ Scripts/run-tests.sh 
Picked up JAVA_TOOL_OPTIONS: -Djava.awt.headless=true
Internet is reachable true
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "customAnnotator" on "project ':GenerateJsonRestModel'", value: "com.googlecode.jsonsch...".

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/sebastian/tmp/android-gradle-template/AppComponentTests/build.gradle' line: 17

* What went wrong:
A problem occurred evaluating project ':AppComponentTests'.
> (class: com/novoda/gradle/test/SupportedLanguages, method: super$1$stream signature: ()Ljava/util/stream/Stream;) Illegal use of nonvirtual function call

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

BUILD FAILED

Total time: 7.935 secs

[wish] Instructions for changing AndroidSample to something else

This looks like really promising work. I pulled the base repo and worked fine, but when I tried to rename the AndroidSample directory and module it went a bit pair shaped. Could not get the ComponentTestRobolectric gradle to sync. This is the error..

./gradlew clean build --stacktrace
root project 'my-data-collector'project ':ComponentTestsRobolectric'project ':GenerateDatabaseContent'project ':MyDataCollector'project ':UnitTestsRobolectric'project ':ComponentTestsRobolectric'project ':GenerateDatabaseContent'project ':MyDataCollector'project ':UnitTestsRobolectric'
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/jeff/Documents/workspace/myData/android/my-data-collector/ComponentTestsRobolectric/build.gradle' line: 6

* What went wrong:
A problem occurred evaluating project ':ComponentTestsRobolectric'.
> The 'android' or 'android-library' plugin is required.

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':ComponentTestsRobolectric'.
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:156)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:38)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:25)
    at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:507)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:82)
    at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:31)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)

I was hoping to find a way to do this so I might be able to script the creation of new projects from this base. Sticking with doing development in AndroidSample is a bit limiting..

Perhaps some instructions on either changing AndroidSample or adding a new Application module would be good. I will keep plugging away..

Error Illegal use of non virtual function call

Hi,
Thanks a lot for this template,
I'm trying to apply the same structure to my project everything worked fine except in my unit test module
i got :
Error:(20, 0) (class: com/novoda/gradle/test/SupportedLanguages, method: super$1$stream signature: ()Ljava/util/stream/Stream;) Illegal use of nonvirtual function call

I added :
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
to my app module thinking maybe it's because of java version but that didn't work.
should i launch the install script install-custom-gradle-test-plugin.sh and use android-studio-robolectric-support.gradle with a specific java version ?

thanks.

Project Structure Question

First, thanks for sharing this. I'm finding it very useful.

Question not an issue: Are there any technical reasons for including the regular instrument tests under AndroidSample and splitting out the other testing into separate projects? Could that all be put under AndroidSample? Or could/should the instrument tests but put into yet another project?

'android' or 'android-library' plugin is required

I have been using android-gradle-template for my project for a while. Since updating to Android Studio 0.8.9 I get this error after opening the AppUnitTests/build.gradle file and then running the test runner:

Error:(19, 0) Gradle: A problem occurred evaluating project ':AppUnitTests'.

The 'android' or 'android-library' plugin is required.

This happens after building the testClasses just before the tests start running. Do you know what could be causing it?

Trying to copy your pattern

Hi - trying to follow your pattern of sub directories with an existing project. I have tried to replicate what you have almost exactly. Yet when I build I get this error:

  • What went wrong:
    A problem occurred evaluating project ':UnitTestsRobolectric'.

    The 'android' or 'android-library' plugin is required.

It thinks that the main Android application doesn't have the android plugin applied, yet it does! Any idea what I am doing wrong?

The directory structure looks like:

android
   build.gradle
   settings.gradle
   app/
       build.gradle
   UnitTestsRobolectric
       build.gradle

Settings.gradle:

  include ':app', 'UnitTestsRobolectric'

My build.gradle in the top most folder has the same settings as yours, except I use build tools 19.0.1.

app/build.gradle has this at top:

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:0.10.+'
    }
}

apply plugin: 'android'
...

UnitTestsRobolectric/build.gradle has this:

buildscript {
    repositories {
      maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.10.+'
        classpath "com.novoda:gradle-android-test-plugin:0.9.9-SNAPSHOT"
        classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:0.4.0'
    }
}

apply plugin: 'java'

test.reports.html.enabled = false     // just clean up dashboard from not generated reports
test.reports.junitXml.enabled = false // just clean up dashboard from not generated reports

apply plugin: 'android-test'
apply plugin: "jacoco"
apply plugin: 'coveralls'
apply plugin: 'idea'

repositories {
  maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}

android {
  projectUnderTest ':app'
}

I see this code in the plugin source so I know it must have found the gradle file for the app, but I can't explain why it doesn't see the android plugin applied!

public void projectUnderTest(String projectName) {

    Project projectUnderTest = project.project(projectName)

    def hasAppPlugin = hasAppPlugin(projectUnderTest)
    def hasLibraryPlugin = hasLibraryPlugin(projectUnderTest)

    if (!hasAppPlugin && !hasLibraryPlugin) {
        throw new IllegalStateException("The 'android' or 'android-library' plugin is required.")

Espresso tests - could they be placed outside the app src folder?

Impressed by this sample project and how you have all 3 levels of tests working along with Jacoco. I've learned a lot by looking at your code and organization of modules.

One thing I really liked: how you put ComponentTestsRobolectric and UnitTestsRobolectric as folders on the same level as AndroidSample. You did a great job of showing how the build.gradle files in sub folders relate to the master build.gradle file and how Jacoco can point to the directory ../AndroidSample for the code coverage.

However, in AndroidSample you have the src folder with main and test subfolders; test subfolder has espresso/instrumentation tests.

Do you think it is possible to move the Instrumentation tests to a subfolder on the same level as the others? I would prefer to have InstrumentationTests folder alongside Unit/Component.

jacoco with espresso, task jacocoTestReport skipped

i use the solution in my project with espresso , task skipped.
my build.gralde

apply plugin: 'jacoco'

android {
  buildTypes {
    debug {
      testCoverageEnabled true
    }
  }
  jacoco {
    version "0.7.1.201405082137"
  }


def coverageSourceDirs = [
        'src/main/java',
]

task jacocoTestReport(type: JacocoReport) {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
    reports {
        xml.enabled = true
        html.enabled = true
    }
    classDirectories = fileTree(
            dir: './build/intermediates/classes/debug',
            excludes: ['**/R*.class',
                       '**/*$InjectAdapter.class',
                       '**/*$ModuleAdapter.class',
                       '**/*$ViewInjector*.class'
            ])
    sourceDirectories = files(coverageSourceDirs)
    executionData = files("$buildDir/jacoco/testDebug.exec")

    doFirst {
        new File("$buildDir/intermediates/classes/").eachFileRecurse { file ->
            if (file.name.contains('$$')) {
                file.renameTo(file.path.replace('$$', '$'))
            }
        }
    }
}

result:

./gradlew  jacocoTestReport --stacktrace
setup
create beta
cleanPublish:/home/sunhao/Project/android/build/apks
:app:jacocoTestReport SKIPPED

BUILD SUCCESSFUL

Unexpected top-level exception when running app

Hello,

After installation (I left everything as is) I get this exception when trying to run App:

Error:Execution failed for task ':App:preDexIntegrationDebug'.

com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/home/.../.../android-sdk/build-tools/android-4.4W/dx --dex --output /home/.../.../.../App/build/intermediates/pre-dexed/integration/debug/GenerateJsonRestModel-2efcc7932f87b8eeed5d2afe940f5caf68cb17e6.jar /home/.../.../.../GenerateJsonRestModel/build/libs/GenerateJsonRestModel.jar
Error Code:
1
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.processClass(Main.java:665)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
at com.android.dx.command.dexer.Main.access$600(Main.java:78)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:596)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
...while parsing com/example/json/Bookmark.class
1 error; aborting

The strange thing is, everyhing is ok if I only build it. This exception arises only when I try to run it.

I tried googling, nothing relevant came up. Any idea on how to solve this would be greatly appreciated.

Thanks!

Voting: Which is your favourite way to support robolectric?

I'm very thankful that the novoda team created a great plugin to support robolectric. I used this plugin for about one year now. The main advantage was the good support for robolectric + espresso where other plugins had some issues. But I disliked that there was not much support. It's looked like they dropped the support. But since short time they are much more active.

The plugin from JCAndKSolutions has the same support like the novoda plugin, but much better integration with android studio when you install the android studio plugin.

Now i think about to drop the novoda example. Would someone dislike this decision? Please tell me also short why.

FileNotFound Exception

Hi,

I'm trying to make my Robolectric tests work with Jacoco support, but it seems that the plugin is not compatible with Dagger as it can not find some class files with '$$' in the filename. For this reason I got a FileNotFoundException when executing the 'jacocoTestReport' task. Is this related to the 'known issue' on this page: http://tools.android.com/tech-docs/new-build-system or is this something that needs to be fixed in Dagger, Android build tools or the Jacoco plugin?

Thanks.

Errors in tests

Just curious, I see some errors when I run the tests currently. Is that intentional, to show us how errors will look in the reports?

Example:
gradlew :UnitTestsRobolectric:testDebug

:UnitTestsRobolectric:testDebug

com.example.activities.DatabaseActivityTest > test_shouldResetAllInputFields FAILED
java.lang.UnsupportedClassVersionError at DatabaseActivityTest.java:64

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.