Open Source Tooling and Automation

Because lab 7 and lab 8 are similar, I’ve decided to combine post blog posts into one.

As with any piece of code we write, a good programmer always tests before releasing (I mean, you should be haha). As your program becomes more complex, you might fix a bug and unintentionally break something else. This is where unit testing can save you! Unit testing is a style of coding which allows you to test a specific function and check it’s output with known data. For example: I have a function that returns true if my email is valid. I know that example@hotmail.com is a valid email, thus my function will return true. But let’s say that a few months went by and I made a modification to the function which causes example@hotmail.com to return false. When I execute my unit tests, I will see that my new changes broke the email function.

There are many unit test design you can use but the one I’m familiar with is JUnit. For this lab, I will be using Jest (Which I’ve never used before).

Jest is a JavaScript unit testing written by Facebook. One of the nicest feature of Jest is that you can tell it to check if your code is following a uniform coding format. For this lab, I set mine to “Airbnb”. One of the features of this standard

Difficult part

The most “difficult part” was adapting to the Airbnb coding style. Everyone has their own coding style but with most programming jobs, you are “forced” to adapt to the company’s coding style. Even though this might not be as difficult as you think, it actually took me longer than it should haha.

Conclusion

Always have a form of unit testing. This will help you create a more stable and uniform program 🙂

Leave a Reply

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