Unit Testing

Learn about the functions and components of unit-level testing.

Unit-level testing

Unit testing is what we use to test how different code pieces behave. We test the code in isolation to ensure it works as expected. Developers generally write unit tests while working on coding a new feature. Unit tests typically run faster than other types of tests. That is why they should make up the majority of our test cases.

A typical unit test has three parts:

  • The code to test: This is the piece of code that we want to test.

  • The expected result: This is what we expect the code to do when it runs.

  • The actual output: This is what the code does when it runs.

Testing functions

We’ll create a function determining if a provided word is a palindrome. A palindrome is a word that, when reversed, is spelled exactly the same. For example, the term “racecar” is a palindrome.

Get hands-on with 1200+ tech skills courses.