Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

testing

What is unit testing?

Sheza Munir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Unit testing is a special type of software testing where separate chunks, or units, of code are tested independently. This helps to test if each component is working properly before integrating them into the main codebase. This is the first stage in the testing process.

A unit can be a function, method, subroutine, module, or object that is tested in isolation from the rest of the code. This testing phase occurs during development.

Advantages of unit testing

Unit testing has many advantages, some of which are listed below.

  • Early debugging:
    Since unit testing is a part of the development phase, it helps in finding bugs early in the software development cycle.
  • Step by step integration:
    Each step (new function, new object, etc.) is tested and then integrated. This step-by-step approach is very helpful when dealing with large codebases.
  • Code reuse:
    Reusing code becomes easier when the test has confirmed that it is working as intended. This shortens the timeline of development.

Types of unit testing

There are two types of unit testing:

  • Automated testing:
    Automated testing uses the UnitTest Framework to develop automated test cases. Depending on how serious the failure is, it may pause the testing of the rest of the code.
  • Manual testing:
    Companies that do not use automated testing use their own manuals for unit testing. Manual unit testing is performed by hand. In other words, the testing is performed by people instead of softwares.

Tools used in testing

Common tools used for unit testing are listed below:

  • NUnit: A testing tool for .NET languages. It is open-source and allows running parallel tests.
  • Junit: A free testing tool for the Java programming language. It tests the data and then the new piece of code.
  • EMMA: An open-source toolkit for the Java programming language. It can run without external library dependencies.
  • PHPUnit: A testing tool for PHP. It allows users to define assertions and how to behave when certain situations are encountered.

RELATED TAGS

testing

CONTRIBUTOR

Sheza Munir
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring