I'm trying to setup my Android project to use Juni...
# gradle
a
I'm trying to setup my Android project to use Junit 5, so in groovy I would usually do
Copy code
unitTests.all {
        useJUnitPlatform()
}
In Kotlin script though I'm doing
Copy code
testOptions {
        unitTests.all(closureOf<Test> {
            useJUnitPlatform()
        } as Closure<Test>)
    }
However I'm a bit annoyed from the
as
clause as without it I get a compile error, so my question is there a way I could do that without explicitly casting to
Closure<Test>
?
m
Maybe something like?
Copy code
testOptions {
        unitTests.all(KotlinClosure1<Test, Test>({this}, this, this))
    }
But I'm not sure it's much better actually. I would just stick to the cast and file a bug the AGP team for them to provide better Kotlin api
a
Yeah, this is not readable either, thanks anyway! I'll try to file a bug for them.
👍 1
m
I don't think that will work for the Android tests
you have to use 3rd party plugin: https://github.com/mannodermaus/android-junit5
t
@Ahmed Ibrahim when you will file an issue - could you post a link to it in this thread? I will star it 🙂
2
a
@tapchicoma Sorry I was offline in the past 6 days so couldn't create the issue. However, here you are I just created a fresh one, let me know if you need to add something to it. https://issuetracker.google.com/issues/150054571
👍 1
@Matej Drobnič Yeah I know, however I'm not intending to use JUnit5 with Android Tests, only plan to use it with unit JVM tests.
m
@ahi AFAIK you still need this plugin even for normal tests if Android Gradle plugin is present.
or did they fix that recently?
a
I had no idea about that, but for me I've written both sample JUnit 5 unit tests and Android instrumentation tests, and both are running as expected with no issues.
m
thanks, I guess I have to check it out again