Testing
Unit Testing
Skip always transpiles your XCTest unit tests into JUnit tests for Android. This means that for now, you can only perform Android tests on compiled 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. If you are using Skip Lite, all of your code is transpiled, so you do not have to limit your testing to bridged types.
Robolectric
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, #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 compiled 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.