Bootcamp Day 3: “Test Yourself!”

The FFT for Day 2 was: “How can you make sure your code works”? Naturally, this sparked an interesting discussion on Day 3 with every member of the Bootcamp class giving their thoughts on the same. Key take-home points for me were:

  1. Document, document, document!
  2. Break code down into smaller, manageable components for simpler debugging.
  3. Get familiar with plugins that can make writing good code easier.

But the FFT was leading up to an important concept: test driven development (TDD). This was something I wasn’t familiar with at all, so it was great to learn all about it! Here’s how it works: you (the developer) write test functions to make sure your code is functioning as intended. So say you have a function add_two_numbers like so:

def add_two_numbers (number1, number2):
number3 = number1 + number2
return number3

If you want to make sure your function really does add the two numbers provided, you can use a test like this:

import unittest # This is the unit testing framework for Python
class MyTest(unittest.TestCase):

def test_add_two_numbers(self):
self.assertEqual(5, add_two_numbers(2,3)

This test basically checks that the two parameters in the assertion assertEqual, are actually equal to each other. In this case, it checks that 5 is equal to the result of the function add_two_numbers(2,3). If you run the program and the output is not as expected, the test fails. Pretty awesome, right? You can test your code before you even write it, just to make sure you stay on course! :) What’s better is that Python has many other assertions besides the assertEqual one.

It’s clear that my programming has been quite amateur because I had never used TDD before (let alone even heard of it). Apart from learning about TDD, Day 3 also had quite a few other tests: an aptitude test, a numerical reasoning test, and several labs. It’s pretty challenging for sure, but I’m loving the learning. I feel really stretched, in the best way. :)

Another highlight of the day? Lunch! We had rice, chicken and kachumbari, which was delicious, but what was even better was getting to know a few more Andela fellows, like Penina, Eugene, and Thomas. Great conversations with great people! :)

Looking forward to Day 4!