Importance of Unit Testing

Importance of Unit Testing 

 In this post, we will discuss about Unit Testing. The below topics will be covered

  • Brief Introduction to Unit Testing
  • Advantages of Unit Testing
  • Limitations of Unit Testing

  1. Brief Introduction to Unit Testing

  • Nowadays Unit Testing is essential in the Software Development process. 
  • Unit Testing ensures the quality of software deliverables. 
  • During recruitment all leading Organizations keep Unit Testing as the primary skill set in their job description.

1.1 Types of Unit Testing

  • Unit Testing is categorized as below
    1. Manual Unit testing
    2. Automation of Unit testing

1.1.1 Manual Unit Testing

  • Developers will write unit tests specific to the module under development and document them.
  • During development, test cases will be executed before committing the source code for that module to the repository.
  • Manual Unit tests will be executed on the target platform on which the final released Software will run. 
  • Developers run the software under development on the target platform with different input scenarios and check the behavior. 
  • In the current industry manual unit testing is not preferred by many organizations. 
  • Below is the Incremental Software development process with manual unit testing.


1.1.2 Automated Unit Testing

  • In Automated Unit Testing, developers implement a test module along with each software unit under development. 
  • The test module developed as part of the software unit is only intended to test the corresponding software unit.
  • Unit Test modules are not part of the release software package.
  • The test module source code will call the Functions/API of the corresponding software unit with different inputs and check the behavior. 
  • In general, test module source code also will be written in the same programming language in which the corresponding software unit is implemented. 
  • Almost all programming languages have a Unit Test framework to ease writing unit tests. For C++ Gtest(Google Test), Java has Junit and Python has PyTest frameworks.
  • Unlike manual Unit Tests, Automation Unit Tests will be executed in the development environment rather than running on the target platform. 
  • Below is  a diagram that explains Automated Unit Testing in the software development process

2. Advantages of Unit Testing


3. Limitations of Unit Testing

3.1 Unable to test runtime performance of Software Module with respect to the target platform 

  • Automated Unit Tests runs on development machines like Windows/Linux/Mac but final release Software may run on different platforms which have less computing power and resources (Memory,CPU and RAM).
  • Unit testing cannot test parameters such as execution speed, memory usage, and power consumption with respect to the target platform on which the software executable will be installed.

3.2 Unit testing cannot guarantee that all user requirements are met

  • Unit testing tests the correctness of individual software units by executing them with different inputs and verifying the results/behavior.
  •  Even though unit tests for individual software units passed it may not guatantee  that software fulfill all user requirements. 

3.3  Unable to test the collaboration of software units with other modules

  •  Unit testing will test the software units by isolating it from other modules.
  • Any dependency on other modules like inter module communicationwill be Mocked( Will be discussed later chapters)
  • Behavior of software unit when interacting with other modules in real time can't be fully tested.
In our next tutorial we will discuss how to write Unit tests for C++ source code with Google Trest Frameowrk. Unit Testing C++ source code with Google Test (Gtest)

Comments

Popular posts from this blog

C++ Virtual Functions uses and Limitations

C++ Constant Expressions Vs Macros