Configure Choose destination directory for Create test dialog kotlin multiplatform
Hi, I'm building a Plugin for Kotlin Test library (https://kotlinlang.org/api/latest/kotlin.test/) to support kotlin multiplatform. (https://github.com/vojtechpesek/Kotlin-Test-Plugin)
You can invoke "Create Test" dialog in Android Studio to create a test for existing kotlin class. Then it shows "Choose destination directory" dialog, where you select the destination directory. For multiplatform projects it does not offer all options.
Suppose we have a kotlin class:
class ThisIsASampleClass {
fun runSample(): Int {
return 3
}
}
Which is in following folder: multiplatform/src/commonMain/kotlin/com/sample/multiplatform/ThisIsASampleClass.kt
When using default JUnit4 template in "Generate Test" dialog, the "Choose destination directory" allows me to only select androidTest folder. See image below. But the test should be in commonTest, since the class is in commonMain.
At this moment I don't know how to alter this behaviour. For the test generation I am using com.intellij.testIntegration.createTest.TestGenerator. My main problem is that I do not know where to start or how to configure this.
Is it possible to:
- hook into the destination directory list of folders?
- Add a custom field to "Create Test" dialog?
- Offer self written "Choose Destination directory" that I can configure to reflect different Main and test sources? (this also involves ios, js or other possible targets, not just commonMain)
Any help or guidance on this topic is very much appreciated!
Folders inside multiplatform project:
Please sign in to leave a comment.
Hi Vojtech,
I'm not familiar with the Android test creators, so I suggest taking a look into its implementation to see if there is any customization possibilities.
If it's not possible to customize it, you can create a custom com.intellij.testIntegration.TestCreator and build the dialog with all the required fields and behaviors. You can look at the Java test creator to get inspiration:
https://github.com/JetBrains/intellij-community/blob/master/java/java-impl/src/com/intellij/testIntegration/JavaTestCreator.java
or see how it is done in other open source plugins:
https://jb.gg/ipe?extensions=com.intellij.testCreator
Hi Karol,
i will report my findings here. The TestGenerator has only one override method and it is called after clicking through the UI dialogs. It is not possible to customize that or at least i did not found any options to do so.
I've been looking why it does not show commonMain as available target directory. During the UI dialog creation the package is filtered out :
It can find the commonTest module is depending on the commonMain but is filtered out. I did not find out why. It might have to do something with https://issuetracker.google.com/issues/231701341.
Anyway, for my purpose, i can infer the correct package name from the class name.
Thanks for the sources, it was helpful.