Writing Unit Tests & Working with Table Views

I felt like I was able to get a lot done today. The real reason for this is that my parents are watching my daughter, so while she plays at the farm and the spray park, this mom gets to learn new tricks. It’s going to be hard once we get back on the road (have you checked out my travel blog?) to have quite as much time for coding with no childcare. My husband is currently freelancing his dev skills, so we will trade off time to work.

One part of today’s tutorial felt oddly familiar to me: unit tests. I wrote a new class, which defines a “meal”. A meal has 3 properties: name, rating, and photo. So I wrote unit tests against this class, to check for error states, and also to check that the class is working as expected. I tested with a zero rating, positive rating, a rating that exceeds the maximum, a negative rating, and an empty string.

I passed parameters to the Meal class and asserted that the class either did or didn’t initialized based on if the values were valid or not. I remember writing a lot of unit tests in my last coding job (I was a C# developer) so this was a really nice refresher. Unless you are coding on a regular basis, you forget a lot of things. It has been awhile since I’ve written code, so it’s comforting when I can actually remember how to do something!

Once I got past writing the unit tests for my new class, I created another scene in my storyboard. This was exciting – up until now, my app was just one screen. I changed the entry point of the app to be the table view that I just created. This table view is going to display a list of meals, ratings, and photos. I configured a custom cell, that includes my 5-star ratings control, a photo, and label for the meal name. I unchecked the “user interaction” property on the ratings control since it’s static on this scene.

I also created my first array (woot…ok, just kidding, I’m really not that excited about it) and loaded it with sample data to display in the table view. Here I used instances of my Meal class and then loaded them into the array and passed them dummy parameters…for now.

Next up is displaying the data in the table view. That’s what I’ll work on next time I sit down to code!

BTW – how do you like this tire cover we bought for our RV?

Leave a Reply

Your email address will not be published. Required fields are marked *