igor.wojda
02/20/2018, 6:04 PMcreate 2 templates, one for test class and one for test method
.
First of all, I tried to setup Kotlin specific template for Junit4 Test Method
template, but there is none. Yes we can use java code that will be converted into Kotlin, but we would lose some Kotlin specific constructs like latent
...but, unfortunately even Java version does not work at all
https://youtrack.jetbrains.com/issue/KT-22937
I also tried to generate whole test class from Junit 4 Test Class
template, but again lack of Kotlin specific language constructs and J2K conversion process makes use of templates a bit unpredictable and problematic eg. I want lateinit and yes I want empty class with empty body (J2K removes this body, but I need it to add tests there)
https://youtrack.jetbrains.com/issue/KT-22120
Since both of above code templates
failed to generate proper test method/class I started looking into live templates as a hack or way around the problem. I was able to create a template for generating test method. With test class template I used groovyScript expression
(painful to implement, annoying to test, impossible to debug?) to process some strings but still failed a bit because I was not able to retrieve the path of the current file to generate the proper package name (for empty Kotlin file where I want to use this template). I described my ‘get file path’ problem on 3 separate groups, 0 answers…
My point here is that in Kotlin there are multiple problems with Kotlin code/file/live templates and currently templates are unusable or VERY difficult to use. I think someone should look at it at ‘bigger picture’ and try to fix “Kotlin-template user experience’Czar
02/20/2018, 6:12 PMigor.wojda
02/22/2018, 6:29 PM