I am working on creating unit tests for my iOS por...
# multiplatform
h
I am working on creating unit tests for my iOS portions of my shared library but I am running into issues copying resource files from my project onto devices and simulators for the test. Does anyone know of a way I can do this?
j
Can you be more specific? What exactly do you do to copy the stuff (build.gradle.kts snippet eg.?), and what exact error message are you getting?
h
I have a data file that I use for testing. On JVM unit tests I can access right from the resources folder but on iOS it isn't accessible from the simulator.
If there is some way in code to include the resources directory in tests on the iOS device/simulator that would be amazing and simplify my unit tests so much.
My current thoughts would be to Base64 the file and put that directly into my code and write it out at the beginning of the test, which makes maintenance a nightmare.
j
What works for me is that I have a folder with the files I need in the Resources of my iosApp, and I've added the folder via right-click on it, selected Add files to "iosApp", selected the folder (not the files!), and unchecked "Copy items if needed" and checked "Create folder references". That way, I can freely copy files into this folder, and they appear in the bundle. Then I can read them via Bundle.main.path(forResource: "name", ofType: "ext") (Swift) or NSBundle.Companion.mainBundle.pathForResource("name", "ext") (Kotlin). Is that what you are looking for?
[And just keep the folder empty for the release builds.]
h
Does this only work in xcode, or can I use that in Studio, and my build server?
j
You have to do the initial set up in xcode, but then it is just a matter of doing the build.gradle.kts right, so I'd say you can do from Studio and build server too.
👍 1