One of the qualities of a good software developer is high attention to detail but nevertheless, errors can escape even the very best of developers. That is why testing and debugging is a huge part of the Software Development Life Cycle (SDLC). Software testing even has its own field of specialization; some organizations hire testers who are specialized in testing software, instead of assigning the responsibility to software developers. However, every software developer needs to know how to test their own code to produce quality deliverables.
Four Levels of Software Testing
The
"Software Testing Fundamentals" website explains how there are four levels of testing in the SDLC namely: unit testing, integration testing, system testing and acceptance testing.
In
unit testing, individual components of a software application are tested to validate that each component performs as designed.
In
integration testing, individual components are combined and tested as a group to expose faults in how they interact with each other.
In
system testing, the complete, integrated system is tested to determine if it meets specified requirements.
In
acceptance testing, the system is tested to evaluate its compliance with business requirements and determine whether it's acceptable for delivery.
Unit Testing
The website also describes unit testing in detail. A unit/component is the smallest, testable part of a software application like a program, function, procedure or method. These units are tested using a software testing method called the
"white box testing method", in which the internal structure of the item being tested is known to the tester. Unit testing is often performed by software developers themselves. Testing is based on an analysis of the internal structure of the component or system.
Some of the benefits of unit testing according to Ekaterina Novoseltseva (2017) is that it improves the quality of code, bugs are found at an early stage and it helps in maintaining and changing the code.
An Example of a Unit Test
Below is a method that truncates a string:
public static class StringExtender
{
public static string Truncate(this string source, int length)
{
//If source is null, return null.
if (source.Length > length)
{
source = source.Substring(0, length);
}
return source;
}
}
The following code is a unit test built with MSTest on Visual Studio 2017:
[TestClass()]
public class StringExtenderTests
{
[TestMethod()]
public void TruncateTest()
{
//arrange
string source = "Original Source";
int length = 0;
string sourceTruncated = string.Empty;
//act
sourceTruncated = source.Truncate(length);
//assert
Assert.AreNotEqual(source, sourceTruncated);
}
}
The code that is added in the test method tests whether the original string has been modified to indicate that the
truncate method has been implemented. When you run the test you will see whether the test failed or was successful. When the test passes it means the truncate method was executed successfully.
Interview with Lulu Ndhlovu
Lulu is a software developer with 4 years of experience working mainly with web applications. It was a delight interviewing her to gain insight into the importance of unit testing.
Q: Where did you first learn about unit testing?
A: In my first job at Boxfusion
Q: How often do you practice unit testing?
A: Not often I only did it once.
Q: How has it impacted your performance and quality of work?
A: It was very convenient because we were doing testing with Paypal integration so that's something important you need to make sure is working. We tested the methods that were necessary that needed to call the services for Paypal.
Q: Do you recommend unit testing to all developers and organizations?
A: Yeah. If you have the time in your project.
In conclusion, unit testing is the best way to ensure that components of your software application work individually. Every developer should acquire the skill especially for projects that cannot afford to have minimum security.
References:
- Software Testing Fundamentals (n.d.) Software Testing Levels [online] Available from: http://softwaretestingfundamentals.com/software-testing-levels/ [Accessed on 10 October 2018]
- Software Testing Fundamentals (n.d.) Unit Testing [online] Available from: http://softwaretestingfundamentals.com/unit-testing/ [Accessed on 10 October 2018]
- Software Testing Fundamentals (n.d.) Unit Testing [online] Available from: http://softwaretestingfundamentals.com/white-box-testing/ [Accessed on 10 October 2018]
- Novoseltseva, E. (2017) Top 8 Benefits of Unit Testing [online] Available from: https://apiumhub.com/tech-blog-barcelona/top-benefits-of-unit-testing/ [Accessed on 10 October 2018]