Hi guys! Am I able to run ios tests with `CocoaPod...
# kotlin-native
f
Hi guys! Am I able to run ios tests with
CocoaPods
? The documentation says that if the module uses
CocoaPods
libraries, it can be build
only from Xcode
. 😞
o
Nope, according to https://github.com/JetBrains/kotlin-native/blob/master/COCOAPODS.md#workflow you just need to build XCode project, and can be done with CLI tools, not from XCode
s
@olonho could you provide the exact quote for this? AFAIK, if Kotlin/Native imports dependencies from CocoaPods, then it can be built only from Xcode.
If I understand correctly, you mean using xcodebuild. Unfortunately, this is not enough to run arbitrary Gradle task, which is required to run tests. To run tests, one could probably add a script build phase to Xcode (maybe to an additional target).
p
You can write a thin wrapper with a XCTest to trigger the kotlin function kotlin.native.internal.test.testLauncherEntryPoint(). For that function to be available create a test framework (not executable) and add this framework. @svyatoslav.scherbina is it planned to make _ generatedSuites accessible? Then we could dynamically create a XCTest Suite per Kotlin TestSuite
s
We don’t have specific plans for this. Btw, inaccessible
_generatedSuites
is not the only blocker for running Kotlin tests from Xcode with XCTest. For example, the framework doesn’t include tests by default, i.e.
_generatedSuites
is empty. Do you have any suggestions on how to deal with this?
p
We currently generate a test.framework that includes the test code and our runtime code for iOS from Kotlin. This is then attached to a regular xctest case
Copy code
import XCTest
@testable import iOSDeviceTest

class iOSDeviceTestTests: XCTestCase {

    func testKotlinNativeFramework() {
        XCTAssert(runAllKotlinNativeTests() == 0)
    }
}
Copy code
fun runAllTests() = kotlin.native.internal.test.testLauncherEntryPoint(emptyArray())
Finally, this is how we generate the “test.framework” in MPP Plugin
Copy code
iosArm64("ios") {
        binaries {
            framework('test', [RELEASE]) {
                compilation = compilations.test
                linkerOpts += ['-framework', 'UIKit']
            }
        }
    }
s
I suppose this doesn’t help to run Kotlin tests from Xcode when using CocoaPods plugin.
f
Thanks! @Paul Idstein I added the configuration you had said but the framework wasn’t generated:
Copy code
targets {
        final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") ? presets.iosArm64 : presets.iosX64

        fromPreset(iOSTarget, 'ios') {
            binaries {
                framework('client')
                framework('test') {
                    compilation = compilations.test
                    linkerOpts += ['-framework', 'UIKit']
                }
            }
        }
    }
Am I doing it right?