actual typealias for androidTest only

Viewed 33

I need to run some instrumented tests (androidTest), mainly because I need to test the AndroidOpenSSL provider, but at the same time I need to mock Android HW related APIs, which are final.

While there is Mockito support for Final Classes, it appears to have many limitations.

The most reasonable way I found so far is to use kotlin expect / actual typealias to use the platform API under release/debug, and to use my custom class under a build type just for tests.

I add the following on build.gradle:

buildTypes {
    ...
    create("platformMock") {
        initWith(getByName("debug"))
    }
}
testBuildType "platformMock"

And my source structure looks like:

src
├── androidTest
│   └── java
│       └── com
│           └── example
│               └── learn
│                   └── StuffTest.kt
├── main
│   └── java
│       └── com
│           └── example
│               └── learn
│                   ├── MainActivity.kt
│                   └── Stuff.kt
├── debug
│   └── java
│       └── com
│           └── example
│               └── learn
│                   └── Platform.kt
├── platformMock
│   └── java
│       └── com
│           └── example
│               └── learn
│                   └── Platform.kt
└── release
    └── java
        └── com
            └── example
                └── learn
                    └── Platform.kt

The main inconvenience now is that I must maintain this platformMock build type, selecting it for tests, and that Platform.kt is duplicated for release/debug.

Any simpler way to override a expect / actual typealias just for instrumented tests (androidTest)?

0 Answers
Related