Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Test in Xcode iOS [closed]

I'm not so experience in Objective-C, but I'm I'd like to start develop in iOS using TDD, for this I have few newbie questions :)

What people are using for TDD for iOS? I was think in use the Test framework that already have in Xcode, is it good? or any better options?

I was trying to do some exercises for unit test, and I was creating an Example, where I have a TableViewControllerClass, using CoreLocation, with this methods:

    -(void)startFindLocation
    {
        [self.cllManager startUpdatingLocation];
    }

    -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
    {
        [self.cllManager stopUpdatingLocation];
        CLLocation *actualLocation = [locations lastObject];

        NSLog(@"latitude: %f", actualLocation.coordinate.latitude);
        NSLog(@"longitude: %f", actualLocation.coordinate.longitude);
    }

What I would like to test, is very simple, is to see if the CLLocation has a latitude and a longitude, instead of using NSLong. For that I really need to alloc and init this TableViewController class in my Test Class? or there's any framework, similar to Rspec (for example, ruby/rails), where I can check if a specific label in the application screen has this value of latitude and longitude?

Regards

like image 361
Fernando Avatar asked May 16 '26 06:05

Fernando


1 Answers

I have a series of screencasts on iOS TDD, starting with https://qualitycoding.org/objective-c-tdd/

Regarding your particular question, a unit test needs to check results in one of three ways:

  1. Return value verification
  2. State verification
  3. Behavior verification

I don't see anything in -locationManager:didUpdateLocations: that leads to any of these. Perhaps you want to TDD a helper method instead.

like image 90
Jon Reid Avatar answered May 17 '26 22:05

Jon Reid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!