Code Monkey home page Code Monkey logo

Comments (8)

nenick avatar nenick commented on July 22, 2024

Lets find it out who needs work ...

Get you coverage report when you run connectedCheck (espresso tests)? When yes then dagger + jacoco works together and it should be possible with robolectric.

Create a sample project setup with dagger to show us your error, then we can try out. Class not found mean most times it is missing in the classpath. Try out to play with this line classDirectories = fileTree(dir: '../AndroidSample/build/classes/debug', exclude: 'com/example/R*.class')

What is your intention to use dagger? Maybe it would be enough to use AndroidAnnotions as your dependency injection framework.

from android-gradle-template.

josomers avatar josomers commented on July 22, 2024

I'm planning to create a few sample applications in the upcoming week. I'll keep you informed.

from android-gradle-template.

josomers avatar josomers commented on July 22, 2024

It's about injection which is not compatible with jacoco I guess, both Butterknife as Dagger are not compatible after testing some things.

from android-gradle-template.

dpreussler avatar dpreussler commented on July 22, 2024

As it's not mentioned here, at least those projects can have coverage with excluding the generated classes: exclude: '/$.class'

from android-gradle-template.

nenick avatar nenick commented on July 22, 2024

have you tried it or maybe @josomers could you try it please?

current i don't plan to include dagger or butterknife until someone has a good reason for me. But I would be glad if someone found a way to get it work and share it with me. Then i will mention it in the wiki how to include dagger or butterknife and get this code under test.

from android-gradle-template.

josomers avatar josomers commented on July 22, 2024

Very nice suggestion by @dpreussler! I tried and modified it a little, but this is my working solution: https://gist.github.com/josomers/9f90b017e321c54bb918

Make sure to replace 'my-project' with the name of your project.

from android-gradle-template.

nenick avatar nenick commented on July 22, 2024

here is a solution without excluding the generated files http://chrisjenx.com/gradle-robolectric-jacoco-dagger/

the main part is to add following part inside jacocoTestReport { }

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

from android-gradle-template.

sunhao111999 avatar sunhao111999 commented on July 22, 2024

@nenick @josomers

i use the solution with my project , 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

Total time: 21.856 secs

from android-gradle-template.

Related Issues (20)

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.