skippy-io / skippy

Mono-repo for all Skippy projects.
https://www.skippy.io
Apache License 2.0
19 stars 2 forks source link

issues/162: feat(android): Add AndroidTestSourceSetCollector #182

Closed Link184 closed 1 week ago

Link184 commented 1 week ago

Extract all the android source sets using kotlin gradle plugin and JavaCompile task

Issue: https://github.com/skippy-io/skippy/issues/162

Link184 commented 1 week ago

@fmck3516 now we have the right source sets but the plugin is still not working. Maybe we also need to provide the exact path to the compiled class files? Right now we provide the path to /build dir only, in android class files are located not in build/classes/java

fmck3516 commented 1 week ago

@fmck3516 now we have the right source sets but the plugin is still not working. Maybe we also need to provide the exact path to the compiled class files? Right now we provide the path to /build dir only, in android class files are located not in build/classes/java

classesDirs needs to point to the output folders (not the source files):

build/intermediates/javac/debug/classes
build/intermediates/javac/debugUnitTest/classes
...
build/tmp/kotlin-classes/debug
build/tmp/kotlin-classes/debugUnitTest
....

buildDir pointing to build is okay (it's only used for https://www.skippy.io/docs/#coverage-for-skipped-tests).

fmck3516 commented 1 week ago

I also took a stab: https://github.com/skippy-io/skippy/pull/183/files

I have to read up more on the variants stuff (debug vs. release) - I just hard-coded the plugin to consider the debug variant.

fmck3516 commented 1 week ago

Love the PR 👍

I assume that there is more work required (see below), but I'm tempted to merge it since it's a great first step towards Android support.

One thing that might cause issues is the fact that outputs for the release and debug build types are now cobbled together in test-impact-analysis.json:

{
    ...
    "classes": {
                ...
        "16": {
            "name": "com.example.testskippy.JavaSkippy",
            "path": "com/example/testskippy/JavaSkippy.class",
            "outputFolder": "build/intermediates/javac/debug/compileDebugJavaWithJavac/classes",
            "hash": "CFA4BEFE"
        },
        "17": {
            "name": "com.example.testskippy.JavaSkippy",
            "path": "com/example/testskippy/JavaSkippy.class",
            "outputFolder": "build/intermediates/javac/release/compileReleaseJavaWithJavac/classes",
            "hash": "CFA4BEFE"
        },
                ...
        "22": {
            "name": "com.example.testskippy.MyJavaSkippyTest",
            "path": "com/example/testskippy/MyJavaSkippyTest.class",
            "outputFolder": "build/intermediates/javac/debugUnitTest/compileDebugUnitTestJavaWithJavac/classes",
            "hash": "2E272DFA"
        },
        "23": {
            "name": "com.example.testskippy.MyJavaSkippyTest",
            "path": "com/example/testskippy/MyJavaSkippyTest.class",
            "outputFolder": "build/intermediates/javac/releaseUnitTest/compileReleaseUnitTestJavaWithJavac/classes",
            "hash": "2E272DFA"
        },
                ...
    },
    "tests": [
        {
            "class": 22,
            "tags": ["PASSED"],
            "coveredClasses": [16,17,22,23]
        },
        ...
    ]
}

At runtime, Skippy picks the first entry that matches a given class name:

https://github.com/skippy-io/skippy/blob/4d0a4a6f76634cf4f239d2b68d716e9167b34ff4/skippy-core/src/main/java/io/skippy/core/TestImpactAnalysis.java#L137-L139

Have to think about how to properly separate the data for the release and debug build types.

BTW: That's not directly related to Android-based builds. I already had that on my radar: https://github.com/skippy-io/skippy/issues/133