This tutorial explains what is Thread Testing, when, and how to perform it, the types of thread-based testing, and the challenges faced:
Thread testing is a software testing technique that is used to test applications that are client-server-based.
Thread-based testing should be performed at the initial stages of Integration testing so that the key functions can be tested/verified for a specific task/program or thread.
Table of Contents:
Why Thread Testing
When the components are integrated, it is necessary to check if the system will work as expected or not and if all the transactions will happen as per the requirement or not. Thus Thread based testing comes in to test the same.
This testing is done by integrating the threads progressively at all the levels starting from the subsystem to the complete system i.e. the whole system. All the system activities move forward with the threads only.
Thread definition helps to share the functional background and thread execution details between the developers and developers testers.
About Threads
A thread is the flow of control in a process. It is the smallest task of the system that can be run.
Example
A web browser might have one or more threads running viz. one thread to display images and text and another thread to retrieve data. In certain cases, a single application must be required to serve all the processes.
Creating multi-threads is the best solution for the same, else multiple requests will be sent to the server by the client and it will take time to acknowledge the requests one by one. Multi-thread will help to respond to the requests simultaneously.
When And How Is Thread Testing Performed
It should be done at the initial stage of the System Integration testing.
Integration testing is performed by integrating different modules in a planned way. The integration plan is followed for the same that specifies the order in which the modules will be integrated to make the complete system.
Listed below are the techniques for executing Integration testing:
- Big-Bang approach
- Top-down approach
- Bottom-up approach
- Mixed approach
Let’s see each technique in detail.
#1) Big-Bang Approach
The big bang approach is used for small systems only as all the modules are integrated and tested in only one go.
Any issue found during this approach is difficult to localize as the issue can be from any of the integrated modules. Therefore, debugging issues found are very expensive to fix in this approach.
#2) Top-Down Approach
The top-down approach is done using the stubs i.e. once the top-level module has been tested, the immediate subroutines are integrated and tested.
Stubs are the programs that simulate the effect of lower-level routines and are called by the routines under test. Thread testing uses a top-down approach.
#3) Bottom-up Approach
In the bottom-up approach, all the subsystems are tested individually, and then the complete system is tested. The reason behind testing all the subsystems separately is to test the interface among all the modules that are a part of the subsystem.
This technique requires test drivers i.e. the program that calls the other modules and provides the same output as the actual product.
#4) Mixed Integration Testing
This technique is a combination of both top-down and bottom-up approaches. Hence it is called Mixed Integration Testing.
Key Points To Perform Thread-Based Testing
- While performing thread testing, threads, or small functionality is integrated and tested. The testing done is incremental testing at a sub-system level and then as a complete system.
- At the initial stage itself, the integration testers get a good idea and knowledge for what to test further.
- Integration testers have to apply and execute scenarios both positive and negative within the thread boundaries only. They have to decide on a thread testing approach to be followed to cover exceptional cases and boundary cases as well.
- The thread definition provided by the developer to the tester helps to test the thread accordingly by the integrator testers. Any further information required by the tester can be answered in the thread review process.
- The thread processes work for integration processes rather than for end-to-end-development processes.
- To test multi-thread functionality, let the multiple instances of the application or program to be tested be active at the same time.
- Run the multi-thread program on different hardware.
- Thread testing is a form of session testing in which sessions are formed of threads. A formed thread doesn’t need to be a session.
Types Of Thread Based Testing
Two types of thread-based testing are performed:
- Single Thread testing
- Multi-Thread testing
#1) Single Thread Testing
Single thread testing tests one transaction at a time. The wait time for the client to get a response to its request could be a bit longer as it will be able to serve or respond to one client at a time.
This testing helps the tester to understand and test the logic of the program or written code.
#2) Multi-Thread Testing
Multi-thread testing tests several active transactions at the same time. In this case, separate threads are created for the requests of the client. Whenever a request is made, a thread is created for the service or responds to the request.
A transaction that was working fine in the single thread testing can fail while testing in multi-thread and also can interfere with other threads and functionalities and stop them from working as expected.
Is a multithread approach better than a single-thread approach?
Multi-threaded applications are better than single-threaded ones as they improve the performance of the application. Multi-threading allows many resources to work on an issue/request at the same time.
Challenges While Doing Thread-Based Testing
While performing thread-based testing, the tester faces several challenges that impact the performance, time, and cost of testing.
- Writing unit test cases for multi-threaded code is challenging.
- When multi-thread testing is being done on different hardware, it varies in size, storage capacity, memory, problems, etc.
- Testing scenarios for both single threads and multiple threads are different.
- In multiple-thread testing, reproducible tests for unit tests should be programmed.
Advantages/Disadvantages Of Multi-Threading
Multi-threading has many advantages as well as disadvantages. As a tester knowing the same helps them to test and break the testing process accordingly.
Advantages
- Multi-threading increases the responsiveness to the user. The application may let the program run even if part of the application gets blocked.
- Resource sharing is another advantage as threads share the resources of the process they are related to or belong to.
- Creating threads is economical as it shares the resources to which they belong.
Disadvantages
- Complex testing process
- Results are very unpredictable.
- Writing a program becomes more difficult.
- Deadlock occurrence.
What Is Deadlock
When multi-threading is done, the thread gets into a wait state if the resource is not available.
The waiting state might not change for the thread as the resource requested is held by other waiting threads. When such a situation arises that’s called Deadlock.
Difference Between Thread And Processes
Let’s understand the differences between Threads and Processes:
S.No | Thread | Process |
---|---|---|
1 | Thread is a lightweight process. | The process is a heavyweight process. |
2 | If the server thread gets blocked, a second thread of the same task can run and complete the process. | If the server process gets blocked, other processes cannot run till the time blocked server process gets un-blocked. |
3 | Threads do not isolate, they share memory. | The process is isolated. |
4 | Creating threads, context switching, termination takes less time in the thread. | Creating threads, context switching, termination take more time in processes. |
5 | Thread refers to the specific task of a process. | Process refers to the execution of any program. |
6 | Resources utilized are very few in the thread. | Resources utilized in processes are more. |
7 | Threads cannot be divided further. | Processes can have multiple threads. |
Difference Between Thread-based And User-based Testing
S.No. | Thread-based Testing | Use- based Testing |
---|---|---|
1 | Threads are integrated and tested individually. | Testing starts with classes which are not dependent on each other i.e. are independent. |
2 | Regression testing is performed to make sure that nothing gets impacted. | Once testing of independent classes is done then dependent classes are tested. Dependents are the ones that depend on the independent classes. This series goes on till the time the complete system is built. |
3 | Thread-based testing integrates the classes that are essential to acknowledge input or event of the system. | Use-base testing integrates the classes that are essential to respond or acknowledge the use case. |
Frequently Asked Questions
What is Thread Testing?
Thread-based testing is a methodology that is performed during the early phase of integration testing. Threads or programs are integrated and tested incrementally in a subsystem and then as a whole system.
Which testing is done first?
Usually bottom-up testing is done first and then top-down testing is performed.
What is Top-down Testing?
Top-down is an integration testing technique where testing is done using stubs i.e. when lower-level components are not yet ready to test the integration, stubs (temporary modules) are created to get the same output as in the case of actual modules.
Conclusion
Thread-based integration testing plays an important role in testing the major functionalities or the specific task or thread. This methodology is best for client-server-based architecture.
While performing thread testing, the tester has to face many challenges, however, has many advantages as well which makes it easy and reliable to perform. It lets the testers test all the transactions and verify if it is working as expected and as per the requirement.
It is impossible to test all the transactions/events to complete the thread testing because of which, it is divided into single and multi-thread types.