https://kotlinlang.org logo
#ksp
Title
# ksp
n

Nikhil

09/19/2023, 5:50 AM
Hello! I have a question (could be dumb), I'm generating unit test files/classes with KSP. I wanted to ask if there is any way that the unit test classes are created/generated in the
src/test/kotlin
directory? right now they are generated in the default ksp-generated directory. I could think of writing a Gradle task for moving them to the appropriate directory after processing/generating them with Ksp. Is there any other better way?
e

estevanfick

09/19/2023, 1:00 PM
g

glureau

09/19/2023, 2:25 PM
Do you want to test your generated code or do you want to run the tests you've generated?
m

Mike Dawson

09/19/2023, 4:21 PM
If you simply want to generate output directly into the test directory, you can use kspTest as per https://kotlinlang.org/docs/ksp-multiplatform.html
If you want to test what your ksp processor generates does what it is supposed to do, my approach is to have a test module (which has processed annotations and uses the KSP module) and then use unit tests to make sure that the generated code does what it is supposed to end-to-end.
n

Nikhil

09/20/2023, 5:05 AM
Ah yes! Got it! Thanks a lot, everyone! I will check that 👍
2 Views