9
votes

Lets say I have a pod DevelopmentPod.

In the podspec for this pod, i have added a test_spec as follows -

s.test_spec 'UnitTests' do |test_spec|
test_spec.source_files = 'UnitTests/**/*.{h,m,swift}'
test_spec.ios.resources = ['UnitTests/**/*.{json}']
end 

In the Podfile of my project, I have added the pod as follows -

pod 'DevelopmentPod', :path => '<location>', :testspecs => ['UnitTests']

After running pod install, I see that a new target DevelopmentPods-Unit-Tests has been created and using the new scheme in Manage Schemes, I can execute the test cases comfortably.

To integrate this scheme in Jenkins, I will need separate job for this. And I have multiple development pods, which means multiple jobs. Also then will have to consolidate the test case execution data from different jobs. And we can not deterministically say that the code tested by these individual jobs is same as that of the actual build.

What is the best way to solve this problem?

I can easily move all unit tests from different pods to my main app and create a unit test target for the same (which solves the Jenkins job issue too) but then my main app will get cluttered with a lot of unit test code it does not require at all. I would like to keep a pod specific unit test in the pod itself.

1
Just an opinion - your main app should not care about internal tests of your pods. You should rather create a separate set of tests in your main app that test the integration of your app with your pod. - Losiowaty
@Losiowaty I can not agree more. Even I do not want my main app to care about the internal tests of the pods. But the problem is in Jenkins integration. Basically what I want is that a single job on jenkins should be able to run all tests on different pods and then create an ipa if tests succeed. And should also provide a consolidated data of the tests executed. With different schemes being created for unitTests in each pod, I need different jobs to run different schemes and hence this is not scalable at all. - Abhishek729
Again - this proces should not depend on these tests, IMO - the same way it doesn't depend on tests of outside dependencies you use. Your in-house pods should have separate flows and releases, and you should 'trust' that it works, only testing your integration with the pod. Anyhow - to the point - have you looked into xcodebuild command line tool? You should be able to create fairly simple script that runs all your test schemes. - Losiowaty
Would appreciate if you could point me in the correct direction for using the xcodebuild command line tool? Also the pods I am talking about are internal pods, not external 3rd party pods. For exmaple, we have a pod for profile management. So for testing in these individual pods, what is the best way? Should I create podfiles in all these pods and create a project which execute the tests and create jobs for all these projects? - Abhishek729

1 Answers

6
votes

Once you have the target you need to edit your scheme to make it run the tests!

Edit scheme

Then set it to be tested (by adding it to the +)

Include tests in the test list

Also it is added automatically to the build

Add test to build

And its done! :D