What is Unit Testing?

Emine İNAN
Jul 11 · 2 min read
Image for post
Image for post

Unit Testing is a method of testing the smallest piece of code called a unit. The main goal is to validate that each unit of the software performs as expected.

The most important point in Unit Testing, is not to create test cases for everything but to focus on the tests that affect the behavior of the system.

What are the Benefits of Unit Testing?

  1. Detects software bugs early.
  2. Provides more reliable and reusable code.
  3. Reduces cost and development time.
  4. Facilitates changes so speeds up the coding process.

Unit Test Frameworks

Writing a Sample Unit Test

MyClass: includes a function that adds two numbers.

SampleUnitTest: includes methods to perform testing.

The assertEquals() method does the comparison. Checks whether the values ​​given to it are equal or not.

Below is a output in which the methods of this class are tested.

Image for post
Image for post
Test Output

HardwareAndro

It’s a software social hubs.

Emine İNAN

Written by

Computer Engineering Student/Intern at VBT

HardwareAndro

It’s a software social hubs. We will create content: development lifecycle and DevOps feature and test engineering.

Emine İNAN

Written by

Computer Engineering Student/Intern at VBT

HardwareAndro

It’s a software social hubs. We will create content: development lifecycle and DevOps feature and test engineering.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store