Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use unit test cases (added to a development pod as test_spec) in the main app target?

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.

like image 618
Abhishek729 Avatar asked Aug 28 '18 12:08

Abhishek729


People also ask

How do I add a unit test to an existing project in Swift?

To add a unit test target to an existing Xcode project, choose File > New > Target. Select your app platform (iOS, macOS, watchOS, tvOS) from the top of the New Target Assistant. Select the Unit Testing Bundle target from the list of targets.

Is developers perform unit testing in the development phase?

Unit testing is a software development process in which the smallest testable parts of an application, called units, are individually and independently scrutinized for proper operation. This testing methodology is done during the development process by the software developers and sometimes QA staff.


1 Answers

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

like image 73
Pablo Sanchez Gomez Avatar answered Oct 14 '22 04:10

Pablo Sanchez Gomez