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

Add type for KSP #396

Open
Scogun opened this issue Apr 20, 2024 · 1 comment
Open

Add type for KSP #396

Scogun opened this issue Apr 20, 2024 · 1 comment

Comments

@Scogun
Copy link

Scogun commented Apr 20, 2024

Hello!
First of all, thank you for such useful library!
I use it to test my Kotlin Object Multiplatform Mapper.
However, after I added plugin support I didn't find a way, how to add mocked plugin inctance for testing. Something like this.
Could you provide any advice?
Thank you in advance!

@tschuchortdev
Copy link
Owner

I'm not sure I understand exactly what you want to do. Your KSP SymbolProcessor is loading a KOMMPlugin class via ClassGraph, similar to ServiceLocator. And now you want to pass such a KOMMPlugin class to your test? That means you need your compiled KommPlugin to be on the classpath of the test. If you only have a single mocked KOMMPlugin that is shared between all tests, it will be very easy: just set KotlinCompilation.inheritClasspath = true. If each test should have its own mocked KOMMPlugin, things will be more difficult. Probably what you need to do is to find the .class file of the mocked KOMMPlugin class (you can look in the project output directory or use classgraph and ClassLoader.getResource) and then write your own jar file using java.util.jar.JarOutputStream (see stackoverflow). This jar can then be added to the test via KotlinCompilation.classpaths += jarFile.

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

No branches or pull requests

2 participants