Monthly Archives: April 2015

isKindOfClass and XCTest

I learned something very useful today.  My group uses Apple’s XCTest as a framework for test automation.  Because of the way XCTest gets associated with the app, there are certain rules you need to follow that aren’t completely obvious in order to use certain very common features of CocoaTouch.

How XCTest Can Test Your App

When you create a test target to test your app, a separate executable image is built that doesn’t include the components of your app.  When you run a test, your app is run and then the test image is injected into the app process.  The result is that type information comparisons (e.g. isKindOfClass:) only work if the class objects are in the same image.

Fixing Type Comparisons

In order to compare types reliably, you must not include the same source files in both the app target and the test target.  If your project is small, this is a relatively simple task.  However, as your project gets larger and you start using CocoaPods or include libraries in other ways, you need to get a little more creative.

In our case, we use CocoaPods pretty extensively, and we build some of our code in libraries (and therefore separate pods) and some in the application.  The result is that I needed to create multiple pod targets to ensure that no source file was included in both targets.

Other XCTest Tidbits

I ran into this problem because I was building some tests with mocks and other tests without them, and the mocks were located in a separate pod.  In order to get my app to use the mocks, I created an app target that included the mocks directly.  Why, you might ask?  For the following reasons:

  1. My app view controller need access to the data that is being mocked before my tests are run.
  2. Setting a singleton value in a +load method doesn’t work because the +load method in the test target isn’t called
  3. Swizzling in the test target doesn’t work.

References

Download data from mint.com

intuit_mint_logo_detailI’ve been using mint.com for managing my finances since 2009.  It’s a terrific website for budgeting and visualizing how you spent your money.  I recently joined Tableau Software and wanted to employ the power of Tableau against my data.  The first step to doing this is to download my data into a file that Tableau can connect to.  This turns out to be pretty straight-forward thanks to work done by Mike Rooney. He built a Python module called mintapi to pull data from your mint.com account using screen scraping.

If you’ve never used Python before, there are a few extra steps to get it working.  Below are the steps for doing this on a Mac running Mac OS X 10.10 (Yosemite).

1. Install Homebrew.

Homebrew is a package manager for installing commonly-used software modules on Mac OS X.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2. Install the Homebrew-version of Python.

brew install python

Follow instructions in brew output.  Typically this will include statements like this:

pip install --upgrade pip setuptools
brew linkapps python

3. Install mintapi and requirements.

pip install mintapi
pip install pandas

4. Download transactions from mint.com.

Now you’re ready to download your data.

mintapi -t -u MINT-EMAIL-ADDRESS -f FILENAME

where MINT-EMAIL-ADDRESS is the email address you use to log in to mint (e.g. myname@gmail.com), and FILENAME is the name of the file to save the data.  The filename should end in .csv (e.g. mint.csv) to use with Tableau, although you can also specify a .json extension to get the data in JSON format.

To get help on the mintapi command, you can type the following command:

mintapi --help

That’s it.  Super simple.