Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue running Pitest in Android projects with Kotlin #71

Open
phellipealexandre opened this issue Aug 19, 2020 · 8 comments
Open

Issue running Pitest in Android projects with Kotlin #71

phellipealexandre opened this issue Aug 19, 2020 · 8 comments
Labels

Comments

@phellipealexandre
Copy link

Hello!

Firstly, I would like to thank you for this awesome project and for all the contributions you have made so far.

I have been playing recently with this plugin in a large Android project with Kotlin and I am having many issues to run the mutation tests in classes that uses the @Parcelize annotation or uses the when keyword from Kotlin.

I am using version '0.2.5' and I saw a similar issue in Pitest's repository. Basically the error is:

XXX does not contain source debug information. All classes must have an associated source file

I am pasting the complete stacktrace of the error below:

Exception in thread "main" org.pitest.help.PitHelpError: The class com.model.PaymentStakeholder$Creator does not contain source debug information. All classes must have an associated source file
See http://pitest.org for more details.
        at org.pitest.mutationtest.verify.DefaultBuildVerifier.lambda$throwErrorIfHasNoSourceFile$2(DefaultBuildVerifier.java:68)
        at java.util.ArrayList.forEach(ArrayList.java:1257)
        at org.pitest.functional.FCollection.forEach(FCollection.java:34)
        at org.pitest.mutationtest.verify.DefaultBuildVerifier.verify(DefaultBuildVerifier.java:36)
        at org.pitest.mutationtest.tooling.MutationCoverage.verifyBuildSuitableForMutationTesting(MutationCoverage.java:223)
        at org.pitest.mutationtest.tooling.MutationCoverage.runReport(MutationCoverage.java:111)
        at org.pitest.mutationtest.tooling.EntryPoint.execute(EntryPoint.java:121)
        at org.pitest.mutationtest.tooling.EntryPoint.execute(EntryPoint.java:51)
        at org.pitest.mutationtest.commandline.MutationCoverageReport.runReport(MutationCoverageReport.java:87)
        at org.pitest.mutationtest.commandline.MutationCoverageReport.main(MutationCoverageReport.java:45)

I think the main question I would like to ask with this issue is: Does the Pitest Android plugin supports Android projects with Kotlin?

Thanks in advance and have a nice day!

@koral--
Copy link
Owner

koral-- commented Aug 20, 2020

Android projects using kotlin should work. There are few functional tests: https://github.com/koral--/gradle-pitest-plugin/tree/master/src/funcTest/resources/testProjects/simpleKotlin
could you share the minimal project which reproduces this issue?

@phellipealexandre
Copy link
Author

Hi @koral--, absolutely.

In my experience, when working with simple Kotlin classes the plugin works well. The problem appears when we start to work with more advanced Kotlin functionalities such as @parcelize annotations.

I have just created a repository that reproduces the issue: https://github.com/phellipealexandre/MutationTestAndroid

You just need to clone it and execute the command in terminal: ./gradlew pitestDebug

@koral-- koral-- added the bug label Aug 23, 2020
@christophsturm
Copy link

also see the original issue in the pitest repo: hcoles/pitest#764

its possible that this is a kotlin bug. pitest requires source code info for all methods that are not synthetic, and it seems in some cases kotlin omits source code info for autogenerated classes that are not synthetic.

@timothyolt
Copy link

Just an FYI for anyone else looking at this, you can use this to exclude these from mutation testing. Not ideal, but it gets pitest working on the rest of the source.

pitest {
    excludedClasses = ['*$special$$inlined$*']
}

@vojtechpesek
Copy link

vojtechpesek commented Jul 18, 2022

I've updated all of the dependecies on @phellipealexandre example repo (https://github.com/vojtechpesek/MutationTestAndroid/tree/updated-dependencies) and tried to run pitest with ./gradlew pitestDebug but it fails with the following:

9:25:16 PIT >> INFO : MINION : 9:25:16 PIT >> SEVERE : Description [testClass=com.ph.mutationtestandroid.CounterViewModelTest, name=Emit content when count content is requested(com.ph.mutationtestandroid.CounterViewModelTest)]
9:25:16 PIT >> INFO : MINION : java.lang.NoClassDefFoundError: kotlin/reflect/full/KClasses
9:25:16 PIT >> INFO : MINION :  at io.mockk.impl.JvmMockKGateway.<init>(JvmMockKGateway.kt:198)
9:25:16 PIT >> INFO : MINION :  at io.mockk.impl.JvmMockKGateway.<clinit>(JvmMockKGateway.kt:186)
9:25:16 PIT >> INFO : MINION :  at com.ph.mutationtestandroid.CounterViewModelTest.<init>(CounterViewModelTest.kt:54)
9:25:16 PIT >> INFO : MINION :  at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
9:25:16 PIT >> INFO : MINION :  at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
9:25:16 PIT >> INFO : MINION :  at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
9:25:16 PIT >> INFO : MINION :  at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)

Obviously, it has issues with mockk. Solutions like changing to other JDK but that didn't work either. Running the test from Android Studio and command line passes, so this will be something specific to pitest and how it runs the tests. Any ideas?

@szpak
Copy link

szpak commented Jul 19, 2022

Btw, @hcoles, the PIT author has created a new engine which supports Kotlin in a better way than a default one. It is available as a part of the commercial tool/solution Arcmutate. Some projects/companies could be interested in it (however, I haven't been using it).

@hcoles
Copy link

hcoles commented Jul 19, 2022

Thanks @szpak

By coincidence I'm looking at the issue with Mockk (and I think more generally with kotlin annotations) at the moment.

@vojtechpesek
Copy link

I've seen the commercial solution, will ask for trial. It is in beta and not everything works out of the box but I need to take a closer look. Also, @hcoles let me know if you find out something with mockk issue. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants