Testing Machine Learning Systems: Unit Tests

The Smaller The Better

Kurtis Pykes
Pykes Technical Notes

--

Photo by MChe Lee on Unsplash

The first level of testing software is unit testing: they allow us to test the smallest unit of code that makes logical sense to isolate within a system. The cool thing about unit tests is they can be anything you want them to be — although it’s usually a function, class, or line of code in most programming languages.

Ideally, we want our tests to be small. The smaller the better. This is because smaller tests aren’t only more efficient from a practical standpoint — since testing smaller units will allow your tests to run faster — but also conceptually, as it will provide you with a more detailed view of how the granular code is behaving.

Before we move on to how we unit test in Python, here are some of the benefits of using unit tests:

  • You can catch bugs earlier in the development cycle which is important since if bugs appear in released code, it may inconvenience end-users and potentially cause major losses in a business sense.
  • You can make changes to your code with more confidence since any upgrades or refactoring you do will break the system if they are done incorrectly (and will work accordingly if done correctly).
  • You can use them as a form of documentation when done well.

--

--