https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
c

curioustechizen

04/21/2020, 3:38 PM
In a multiplatform module that has
commonMain
and
iosMain
, I want to create a
iosTest
folder that uses iOS-specific code for writing tests to be run on the simulator. I've looked around but I think all the info I find is out-dated. What's the latest on this?
k

Kris Wong

04/21/2020, 3:57 PM
if you have a target named ios, then you already have a source set named iosTest
c

curioustechizen

04/21/2020, 4:06 PM
Hmm, I think the project I'm working on was customized to remove iosTest (maybe it wasn't needed then). I think I can simply create iosTest. But does it automatically have access to XCTest or XCUITest?
k

Kris Wong

04/21/2020, 4:07 PM
no, it does not. it uses kotlin.test
c

curioustechizen

04/21/2020, 4:09 PM
okay. And is it possible to get access to XCTest in iosTest?
k

Kris Wong

04/21/2020, 4:09 PM
not that I am aware of
you would need a test runner that supported that, i.e., Xcode
c

curioustechizen

04/21/2020, 4:11 PM
My objective is: I have a multiplatform library and to test it I need the proper lifecycle classes (Activity in Android and ViewController on iOS). I want to keep the tests next to the library so that they run whenever there are changes to the library
k

Kris Wong

04/21/2020, 4:12 PM
you don't need XCUITest to use a view controller
💡 1
c

curioustechizen

04/21/2020, 4:13 PM
Ah! This is awesome. Thanks a bunch
Wait .. are you saying I can write automated tests for a ViewController without XCUITest?
k

Kris Wong

04/21/2020, 4:14 PM
yes
c

curioustechizen

04/21/2020, 4:18 PM
You can probably guess that my knowledge of iOS is very low 🙂 Can you drive a ViewController's lifecycle in a test by simply calling the appropriate method? For example, if I wanted to test that when
viewDidLoad
happens, then some dependency is called, then can I just instantiate a ViewController and call
viewDidLoad
on it in my test?
k

Kris Wong

04/21/2020, 4:18 PM
i believe you just create the view controller and call
view
c

curioustechizen

04/21/2020, 4:19 PM
Alright I'll research this. Thanks!
🍻 1