stephanenicolas / Quality-Tools-for-Android

1.27k stars 235 forks source link

Code coverage for monkeyrunner using JaCoCo #17

Open jeffcomlin opened 10 years ago

jeffcomlin commented 10 years ago

I tried updating the profile for monkeyrunner as below. But the app crashes when the test runs and this happens only on instrumented build.

I am looking for some insight on this.

Thanks, Jeff

Error:

W/dalvikvm( 6413): VFY: invoke type does not match method type of Lcom/abc/xyz/model/Article;._getPartsMap

Useful link:

https://groups.google.com/forum/#!topic/android-platform/KUwF6KJDb70

Useful comment from the link:

I figured it out!

Turns out that the methods which were not getting executed from the constructor were private and final. However, the byte-compiler of Rhino was emitting invoke-virtuals in the constructor for those methods. dx faithfully converted them and retained their invoke- virtual character. I changed them to invooke-direct with the effect that the compilation now works! Thanks for all your help!

My experiment:

Changed _getPartsMap from private to public. It stopped complaining about _getPartsMap and complained about the next. I change the next method to public and it went on to the once after that.

I don't think making these methods public is a solution, but I am hoping it might have some clues.

Rest of the error message: (Below is the error message I see after Dalvikvm error, mentioned above)

E/AndroidRuntime(14361): FATAL EXCEPTION: main E/AndroidRuntime(14361): java.lang.RuntimeException: Unable to create application .MainApplication: java.lang.IllegalStateException: Could not construct instance of helper class class .persistence.ApplicationOpenHelper ... ... Caused by: java.lang.IllegalArgumentException: Unknown class specified for dataClass: .model.Article

pom.xml:

${jacoco-plugin.version} is set to 0.6.4-SNAPSHOT

<profile>
    <id>monkeyrunner</id>
    <dependencies>
        <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>org.jacoco.agent</artifactId>
            <version>${jacoco-plugin.version}</version>
            <classifier>runtime</classifier>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco-plugin.version}</version>
                <executions>
                    <execution>
                        <id>instrument-classes</id>
                        <goals>
                            <goal>instrument</goal>
                        </goals>
                        <configuration>
                            <excludes>
                                <exclude>*test*</exclude>
                                <exclude>*/test/*</exclude>
                            </excludes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>restore-instrumented-classes</id>
                        <phase>package</phase>
                        <goals>
                            <goal>restore-instrumented-classes</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <configuration>
                    <monkeyrunner>
                        <skip>false</skip>
                        <injectDeviceSerialNumberIntoScript>true</injectDeviceSerialNumberIntoScript>
                        <createReport>true</createReport>
                        <programs>
                            <program>
                                <filename>src/test/monkeyrunner/testFile.py</filename>
                            </program>
                            <!-- Monkey Tests go here <program> <filename>src/test/monkeyrunner/example-test.py</filename> 
                                </program> <program> <filename>src/test/monkeyrunner/example-test2.py</filename> 
                                </program> -->
                        </programs>
                    </monkeyrunner>
                </configuration>
                <executions>
                    <execution>
                        <id>install-app</id>
                        <phase>install</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>run-monkey-runner</id>
                        <phase>install</phase>
                        <goals>
                            <goal>monkeyrunner</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>
jeffcomlin commented 10 years ago

@stephanenicolas Could you please take a peek at this? If you can share some suggestions or pointers, I will definitely look into this further.