In a multiplatform module that has `commonMain` an...
# multiplatform
c
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
if you have a target named ios, then you already have a source set named iosTest
c
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
no, it does not. it uses kotlin.test
c
okay. And is it possible to get access to XCTest in iosTest?
k
not that I am aware of
you would need a test runner that supported that, i.e., Xcode
c
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
you don't need XCUITest to use a view controller
💡 1
c
Ah! This is awesome. Thanks a bunch
Wait .. are you saying I can write automated tests for a ViewController without XCUITest?
k
yes
c
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
i believe you just create the view controller and call
view
c
Alright I'll research this. Thanks!
🍻 1