Menu

Testing

Unit Testing

The SkipUnit module contains Skip’s implementation of the iOS XCTest API for Android. Read its documentation to learn how to run parity tests across both iOS and Android to ensure that your logic is behaving identically on both platforms.

Testing Diagram

Native Considerations

Note that Skip transpiles your XCTest unit tests into JUnit tests for Android, regardless of whether your module is native or transpiled. This means that for now, you can only perform Android tests on native Swift that has been bridged to Kotlin/Java. Unit tests involving unbridged types should be excluded from Android testing.

final class MyNativeSwiftTests: XCTestCase {
    ...
   
    #if !os(Android)
    func testSomeUnbridgedSwift() {
        ...
    }
    #endif 
   
    ...
}

We will offer Android unit testing of unbridged native code in a future release.

There is one additional consideration. The SkipUnit module documentation describes the ability to unit test your code in an Android environment running on your Mac, which can be faster than using the Android emulator. If you choose to test on your Mac, Skip uses a simulated Android environment called Robolectric. Unfortunately in native modules, #if os(Android) checks will evaluate to false under Robolectric, even though you should generally be exercising the Android code path. So Skip also defines the ROBOLECTRIC symbol in your Robolectric testing builds. If you want to be sure that your native Swift takes the Android code path whether running on device, emulator, or in Robolectric, use #if os(Android) || ROBOLECTRIC.

Non-Skip Packages

Testing of native Swift packages that compile for both iOS and Android and do not have a skip.yml - such as the thousands of third-party packages tracked by https://swift-everywhere.org - is discussed in the Porting Guide.

Performance Testing

There is often a significant difference between Debug and Release build performance on Android devices. Always run on a device using a Release build when testing real-world performance.