Write Better Unit Tests

Writing unit tests is not just a formality. Unit tests are as important to an application as the code that runs it. Without them, code is fragile. A twentieth parameter is added to a common function, with yet another conditional added to the end, as backwards compatibility must be maintained and regressions must be avoided. The same bug is fixed for the fifth time this month. The codebase devolves into a house of cards, where even senior developers can’t make significant changes with confidence. To avoid this dystopian future, start writing unit tests for your code with diligence. In this post, we will outline a basic set of guidelines for writing them that will allow you to improve the stability, reliability, and maintainability of your application.

Continue reading Write Better Unit Tests

Using JavaScript’s Fetch with a REST API

If you are at all familiar with modern JavaScript, you have probably heard of, or used, Fetch; a function that allows you to make asynchronous HTTP requests. It leverages ES6 promises to make it easy to define asynchronous behavior. Fetch and promises can be tricky to work with and understand, especially if you are new to them. In this post, we will get a basic understanding of each of them, then discover how we can create a collection of wrappers to make sending requests to a traditional REST API a breeze.

Continue reading Using JavaScript’s Fetch with a REST API

Tips for Testing Django Views

Views are probably the most essential part of a Django application. They provide an interface to your application for users or other external applications. It only makes sense that these need to be well-tested. At first, it can seem difficult and/or tedious to write unit tests for them. However, by decoupling your business logic from your views, testing business logic and view logic separately, and tracking code coverage, you can be confident in the reliability and accuracy of your application’s views.

Continue reading Tips for Testing Django Views