• Test Core Data Model Objects

    To test core data code you have to set up a managed object context in the test fixture. There is a special store type you can use for that.

    - (void)setUp {  
        [super setUp];  
        NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:@[[NSBundle mainBundle]]];  
        NSPersistentStoreCoordinator *storeCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedObjectModel];  
        XCTAssertTrue([storeCoordinator addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:NULL] ? YES : NO, @"Should be able to add in-memory store");  
        _managedObjectContext = [[NSManagedObjectContext alloc] init];  
        _managedObjectContext.persistentStoreCoordinator = storeCoordinator; 
    }
    Read more...

  • You ain't gonna need it

    Today I worked on the tests for my new App. The App is developed using Test Driven Development (TDD). I needed a method which converts decimal numbers into fraction numbers. So with an input of 1.5 the method should give the output 1 ½.

    First I tried to make that method as general as possible. I though about, how to convert something like 0.3. But one important think one has to remember in TDD:

    Only implement code you need to pass the test.

    This is better known as You ain't gonna need it. (YAGNI) It turned out that I only needed fractional numbers with precision of ¼. So the only numbers I had to cover have been 0, ¼, ½, ¾, 1, ...

    This could be done with a simple if-else-if statement.

    This was very simple. The principle "You ain't gonna need it" saved me a lot of time.

    Read more...



subscribe via RSS