Testing
Testing
You have been writing code but it is very important to deliver a bug free code.
Testing is the process of checking the functionality of an application to ensure that it runs
as per requirements and does not have a bug.
The process of identifying and removing bugs or errors from a computer program is
known as debugging. Debugging can be done manually or by using different tools.
Consider the below findSum method which calculates the sum of the first n natural numbers.
public int findSum(int n) {
int sum = 0;
for (int i = 1; i <= n; i++) {
sum = sum + i;
}
return sum;
}
The code runs without an error but the output is not as expected. We need to find out the
error or bug in our code. This is simple if we have a single method but imagine an entire
application where different methods are dependent on one another. In such a case, it becomes
very difficult to find out where the bug is present.
So, we need the help of tools for debugging.
Eclipse provides different tools for debugging. Using these tools, we can run the program
interactively and watch the code during each step of the execution. This makes it easier to
identify the point at which the error was made.
Test types
Software test can be classified in many ways
Based on requirements
Functional testing:
Testing the application against business requirements. Functional testing is done using the
functional specifications provided by the client or by the design specification provided by design
team.
1. Unit test
2. Integration test
3. System test
4. System integration test
5. Incremental integration test
Based on objective
1. Regression test
2. Alpha test
3. Beta test
4. Sanity test
5. Smoke test
6. Interface and Usability test
7. User Acceptance Test
8. Globalization
9. Localization
Non-Functional testing:
Testing the application against client's and performance requirement. Non-Functional testing
is done based on the requirements and test scenarios defined by the client.
In the above example, we can see there are few conditional statements that are executed
depending on what condition it suffice. Here there are 3 paths or condition that needs to be tested
to get the output,
Path 1: 1,2,3,5,6, 7
Path 2: 1,2,4,5,6, 7
Path 3: 1, 6, 7
Boundary Value Analysis
Boundary Value Analysis (BVA) is a Black-Box testing technique used to check the
errors at the boundaries of an input domain. Whenever we do the testing by boundary value
analysis, the tester focuses on, while entering boundary value whether the software is producing
correct output or not.
The name comes from the Boundary, which means the limits of an area. So, BVA mainly
focuses on testing both valid and invalid input parameters for a given range of a software
component.
If (Min,MAX) is the range given for a field validation, then the boundary values come as
follows:
Invalid Boundary Check { Min-1 ; Max+1 }
Valid Boundary Check {Min; Min+1 ;Max-1;Max }
The software system will be passed in the test if it accepts a valid number and gives the
desired output, if it is not, then it is unsuccessful. In another scenario, the software system should
not accept invalid numbers, and if the entered number is invalid, then it should display error
massage.
Example of Boundary Value Analysis :
Requirement: Validate AGE field, which accepts values from 21-60.
We verify the following Boundary Value Test cases:
TC001: Validate AGE by entering 20 [ Min-1]: Invalid Boundary Check
TC002: Validate AGE by entering 21 [ Min]: Valid Boundary Check
TC003: Validate AGE by entering 22 [ Min+1]: Valid Boundary Check
TC004: Validate AGE by entering 59 [ Max-1]: Valid Boundary Check
TC005: Validate AGE by entering 60 [ Max]: Valid Boundary Check
TC006: Validate AGE by entering 61[ Max+1]: Invalid Boundary Check
The main advantage of Boundary Value Analysis is that the testing time is less as the tester will
analyze the data only at the boundaries.
Example:
Consider the below code written by Peter. He wants to test his code using Logic Coverage
technique. Suggest him the most efficient test data set
motorcycle_type="Bike"
years_old=6
if motorcycle_type=="Bike":
if years_old>=5 and years_old<=10:
mileage=45
elif years_old>=11:
mileage=40
else:
mileage=25
elif motorcycle_type=="Scooter":
mileage=35
else:
mileage=20
1) motorcycle_type: “Bike” with years_old(4,8,-1) “Scooter” “Bus”
2) motorcycle_type: “Bike” “Scooter” “Bus”
3) motorcycle_type: “Bike” with years_old(6,9,100) “Scooter” “Bus”
4) motorcycle_type: “Bike” with years_old(2,7,15) “Scooter” “Bus”
Consider the below code snippet. Identify the most efficient test data set for testing the below
code using "Logic Coverage' technique.
if previous_year_percentage>=75 and previous_year_percentage<=85:
scholarship=5000
elif previous_year_percentage>=85 and previous_year_percentage<=95:
scholarship=8000
elif previous_year_percentage>=95
scholarship=10000
else:
scholarship=0
1. 79,87,91,99
2. 78,80,92,99
3. 74,77,90,100
4. 74,75,76,84,85,86,94,95,96,97
Assume we have to test a text field (Name) which accepts the length between 6-12 characters.
Which of the following hash function would lead to the least number of collisions when the
following values are stored,
48,98,34,25,18
1) H(key)=key%9 3,8,7,7,0
2) H(key)=key%10 8,8,4,5,8
3) H(key)=key%8 0,2,2,1,2
4) H(key)=key%3 0,2,1,1,0
Following elements are to be stored in hash table using the hash function h(k)=k%8 in the order
shown:
65,27,50,9,36,43,20
Identify the hash values for which collision occurs.