Category Archives: testing

AppDeveloperKit-String: A Swift library for subscripting, regular expression matching and substitutions

String shortcomings

I really enjoy programming in Swift, but I’ve always been bothered a bit by what I perceived as a couple of shortcomings related to the String class.

Subscripting

There is no support for subscripting a String.

Try the following in a Playground and you’ll get an error:

 let str = "Hello"

 str[1]   // 'subscript' is unavailable: cannot subscript String with an Int
 str[1..<3] // 'subscript' is unavailable: cannot subscript String with an integer range

You can find a mention of this restriction in some source code comments.

Continue reading

Advertisements

Error reporting for complex unit tests

System level unit testing

I was recently putting together the structure for some system level unit tests of a Swift project.   The structure extended beyond a single file for these tests.   I currently have:

  • SystemTests – Base class for a suite of system level unit tests.
  • BasicSystemTests – Class for my first group of unit tests.  Derives from SystemTests.
  • Various utility classes, each specific to a major section of the project.

Here is an example chain of calls coming from a test case:

BasicSystemTests

   func testModified () {
        
        // Test modification to Project
        //
        createProject(name: "Test Project", bundleId: "TestBundleId", appDelegate: "TestAppDelegate", fsConfig: "TestFsConfig", description: "Test Project Description")
        

SystemTests


   func createProject(name: String, bundleId: String, appDelegate: String?, fsConfig: String?, description: String?) -> String? {
        
        // Is Add New button enabled?
        project.verifyAddNewButton(enabled: false)

ProjectTestUtils

    func verifyAddNewButton(enabled: Bool) {
        XCTAssertEqual(addNewButton.isEnabled, enabled, "Add New button enabled = \(enabled)")
    }
  

The problem – what is the path?

My test case has a bug.  When I run the test case, I see the following in Issue Navigator and the source code editor:

Continue reading

SocialCafe iPhone App

I recently completed the first version of a new iPhone app that I’ve been workingicon_socialcafe_black_654 on called the SocialCafe.   The app allows you to take a picture (or pull one from your Camera Roll), add some audio, save to your personal Dropbox account and share with friends via e-mail, Facebook and Twitter.

I just entered a beta testing phase and am actively looking for some testers to provide some feedback.    If you’d like to help out, please visit the homepage at http://www.socialcafe.com and add yourself to the beta sign-up.

Since the app is not yet in the App Store, I am making use of a wonderful service called TestFlight.

SocialCafe Screenshot

You can get a feel for the app before you even sign-up for the beta by looking at some interactive screenshots for a quick walk-through.   You can do this on the SocialCafe homepage or on the other great service that I using called the AppDemoStore.

Here is a direct link to the screenshot demo:

http://www.appdemostore.com/demo?id=5975810833907712

Hope you can help out with beta testing! Looking forward to some feedback.

Functional Coverage and Coverpoints

I recently posted an article called Setting up and using Code Coverage.   As I mentioned there, code coverage is useful for seeing what portions of your code have been exercised.    What code coverage can’t do though is to ensure functional correctness – this is where functional coverage comes into play. Functional coverage allows you to determine when you have exposed your code to a sufficient enough set of stimulus, including hitting corner cases,  that you have a high confidence in its functionality.

My background includes experience as a hardware verification engineer, where the teams I was part of used both code coverage and functional coverage as essential tools in test development.     In the Wikipedia section on SystemVerilog (a hardware description and verification language) there is a nice write-up on Coverage where the difference between code coverage and functional coverage is discussed.

What is a Coverpoint?

I wanted to employ some functional coverage as a guide to my unit test development.   In the SystemVerilog language mentioned above, they have the concept of coverpoints and covergroups (group of coverpoints).   I found a nice document called SystemVerilog Testbench Automation Tutorial where there is some good information about these concepts starting in the section titled “Functional Coverage”.

A coverpoint is essentially a measurement point where an event (such as values taken on by a variable) can be recorded, along with bins for how many times specific values (or range of values) occurred for that event.

Continue reading

Unit Testing View Controllers and Asynchronous APIs

I have an application that I’m working on that uses Parse (a service that lets you persist objects in the cloud, perform queries, etc.).    Calls to the Parse APIs are initiated from the main thread and dispatched to the global queue, thus  completion of these calls happens asynchronously.

I wanted to write some unit tests to verify the functionality of my methods that interface with Parse.

Referencing the View Controller

My initial view controller is called EntryViewController.   This view controller instances a class called ParseConnection which serves as a model for all my Parse interactions.    All calls to methods in ParseConnection from EntryViewController are dispatched to the global queue.  Within ParseConnection, all the API calls are made synchronously in this background queue.

My first challenge was how to get a reference from my unit tests to EntryViewController.   I wanted to do this from the instance setUp method in my test suite class called ContactsOnlineBasicUnitTests, and store this reference in a property.   This setUp method is called before each test case is run.


@interface  ContactsOnlineBasicUnitTests ()

@property (strong, nonatomic) EntryViewController *entryViewController;

@end

Continue reading