Skip to content

Commit a54ad97

Browse files
AUTOMATED Software testing script is added
1 parent 4ee706a commit a54ad97

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#A sample python code to automate the testing of the sample class having basic functionalities of to perform the mathematical operations on the specified operands of that particular function.
2+
3+
# All the required modules which are required across the program are included at the beginning of the code.
4+
import unittest
5+
import sys
6+
7+
A class is written which has different functions to perform the different mathematical operations depending upon the input provided the mathematical operation is performed on the two operands which are taken as input for each function, the class which is written below is the child class of the test case class from the unit test module, with the help of this parenting test case class we were able to use various inbuilt functions of the test case class which help us to write various test case function to test the mathematical results which are calculated by the various function written inside this class
8+
class BasicMathOperationsTesting(the unit test.TestCase):
9+
#Constructor is written which can be used to initialize the various class variable that is required to use throughout this class a variable that is declared inside the constructor of a class can be used across the scope of that particular class
10+
def __init__(self):
11+
pass
12+
13+
14+
# A function is written in which the user is asked for two numbers on which the addition operation is performed, once the user provides the two numbers on which the addition operation is need to perform, that particular operation is performed on the provided two numbers and the result of that operation is stored in a resultant variable and that resultant variable is returned as the return value of this function, and then this return value can be used in various test function which will validate or test the particular operation performed by this function is correct or not by using various inbuilt methods of the test case class
15+
def perform_addition(self):
16+
operation_name = "addition"
17+
print("Enter the first number for {} operation".format(operation_name))
18+
num_1 = int(input())
19+
print("Enter the second number for {} operation".format(operation_name))
20+
num_2 = int(input())
21+
22+
resultant = num_1 + num_2
23+
return resultant
24+
25+
# A function is written in which the user is asked for two numbers on which the subtraction operation is performed, once the user provides the two numbers on which the subtraction operation is need to perform, that particular operation is performed on the provided two numbers and the result of that operation is stored in a resultant variable and that resultant variable is returned as the return value of this function, and then this return value can be used in various test function which will validate or test the particular operation performed by this function is correct or not by using various inbuilt methods of the test case class
26+
def perform_subtraction(self):
27+
operation_name = "subtraction"
28+
print("Enter the first number for {} operation".format(operation_name))
29+
num_1 = int(input())
30+
print("Enter the second number for {} operation".format(operation_name))
31+
num_2 = int(input())
32+
33+
resultant = num_1 - num_2
34+
return resultant
35+
# A function is written in which the user is asked for two numbers on which the multiplication operation is performed, once the user provides the two numbers on which the multiplication operation is needed to perform, that particular operation is performed on the provided two numbers and the result of that operation is stored in a resultant variable and that resultant variable is returned as the return value of this function, and then this return value can be used in various test function which will validate or test the particular operation performed by this function is correct or not by using various inbuilt methods of the test case class
36+
37+
def perform_multiplication(self):
38+
operation_name = "multiplication"
39+
print("Enter the first number for {} operation".format(operation_name))
40+
num_1 = int(input())
41+
print("Enter the second number for {} operation".format(operation_name))
42+
num_2 = int(input())
43+
44+
resultant = num_1 + num_2
45+
return resultant
46+
47+
# A function is written in which the user is asked for two numbers on which the division operation is performed, once the user provides the two numbers on which the division operation is needed to perform, that particular operation is performed on the provided two numbers and the result of that operation is stored in a resultant variable and that resultant variable is returned as the return value of this function, and then this return value can be used in various test function which will validate or test the particular operation performed by this function is correct or not by using various inbuilt methods of the test case class
48+
def perform_division(self):
49+
operation_name = "division"
50+
print("Enter the first number for {} operation".format(operation_name))
51+
num_1 = int(input())
52+
print("Enter the second number for {} operation".format(operation_name))
53+
num_2 = int(input())
54+
55+
resultant = num_1 / num_2
56+
return resultant
57+
58+
# This is a test function which is written for testing the assert equal values which means this test case will be fast if the two values which are passed as parameters to this function are equal, so we have used this assert equal functions to test the various mathematical operations which are performed using the various function which is written above so, for example, let's say perform the addition operation of two variables which are passed as a parameter to that function so to verify that the addition operation performed that particular function is correct or not is then with the help of this function in which first parameter we passed as the actual value will be the value which is the value which is calculated by the function which is written above and the expected value is the value which is expected to be matched with this function so so if both of these values matches then they assert equal test case will be passed on the other hand if the both of these values are not equal then the assert equal test case will fail
59+
def the unit test_for_assert_equals(self,actual_value,expected_value):
60+
61+
actual_value_for_equals = actual_value
62+
expected_value_for_equals = expected_value
63+
self.assertEqual(actual_value_for_equals,expected_value_for_equals)
64+
65+
66+
# This is another unit test case which we have written named assert true that means this function will return require a Boolean value and depending upon the value of the that boolean variable the nature of the resultant test case is dertemined so in this function we are using the assert false functionality of the unit test case class to test the actual and expected output of a mathematical operations so we are passing the oeprand one as the actual value by actual value we mean the value which is actually calculated by the any of the above written mathematical operation let's say multiplication so the resultant of the multiplication function is passed as the first operand to this function and the second operand which is passed to this function is the expected value or which is meant to be the actual output of that function and both of these operations are compared and stored into a variable since the comparison is done on two operands return type is a Boolean value show the variable storing those values will be a Boolean variable and that Boolean variable will be passed to the assert false function if that Boolean variable is having the true value then the test function will be passed on the other hand if the value is fasle the assert true unit test case will be failed
67+
def the unit test_for_assert_true(self,operand1,operand2):
68+
69+
boolean_resultant = operand1 == operand2
70+
self.assertTrue(boolean_resultant)
71+
72+
73+
74+
# This is another unit test case which we have written named assert false that means this function will return require a Boolean value and depending upon the value of the that boolean variable the nature of the resultant test case is dertemined so in this function we are using the assert false functionality of the unit test case class to test the actual and expected output of a mathematical operations so we are passing the oeprand one as the actual value by actual value we mean the value which is actually calculated by the any of the above written mathematical operation let's say multiplication so the resultant of the multiplication function is passed as the first operand to this function and the second operand which is passed to this function is the expected value or which is meant to be the actual output of that function and both of these operations are compared and stored into a variable since the comparison is done on two operands return type is a Boolean value show the variable storing those values will be a Boolean variable and that Boolean variable will be passed to the assert false function if that Boolean variable is having the fasle value then the test function will be passed on the other hand if the value is true the assert fasle unit test case will be failed
75+
def the unit test_for_assert_false(self,operand1,operand2):
76+
77+
boolean_resultant = operand1 != operand2
78+
self.assertFalse(boolean_resultant)
79+
80+
81+
82+
83+
# In The End the main function is written, which has the object of the above-written class Which is used to call all the methods which are written inside the class. the user is provided with the list of menus from which he has to select the mathematical operation which he performs on the two inputs which are going he is going to provide after selecting the appropriate mathematical operation the result of that mathematical operation is presented to the user and another menu is printed from which the type of unit test which needs to be Run on that obtained result is shown, on selecting the appropriate unit test which will run on the result of the mathematical operation that particular test case is Run and depending upon the unit test which is selected by the user appropriate message is shown, that means if the test case is passed it is shown that that particular test case has been passed successfully on the other hand if the test case is failed due to some exception or error that has been encountered during the execution of that particular unit test case, then that particular exception or error message is printed to the user and which line has caused that an exception message is also presented to the user this helps in the debugging so that user can understand by which particular line of code that particular unit test is failing this printing of the menu is done in a recursive manner until the user exits the code execution by selecting the last option which is to exit the code execution.
84+
def main():
85+
86+
run_the unit test = BasicMathOperationsTesting()
87+
88+
while(True):
89+
90+
# from the listed below the list of operations select any one of the operations
91+
print("Select any of the mathematical operations which are listed below:")
92+
print("1. To perform the addition operation and then perform the unit test on the result obtained.")
93+
print("2. To perform the subtraction operation and then perform the unit test on the result obtained.")
94+
print("3. To perform the multiplication operation and then perform the unit test on the result obtained.")
95+
print("4. To perform the division operation and then perform the unit test on the result obtained.")
96+
print("5. To exit from the code execution.")
97+
98+
menu_choice = input()
99+
menu_choice = int(menu_choice)
100+
101+
if menu_choice == 1:
102+
result = run_the unit test.perform_addition()
103+
elif menu_choice == 2:
104+
result = run_the unit test.perform_subtraction()
105+
elif menu_choice == 3:
106+
result = run_the unit test.perform_multiplication()
107+
elif menu_choice == 4:
108+
result = run_the unit test.perform_division()
109+
elif menu_choice == 5:
110+
sys.exit()
111+
112+
print("Select any of the unit tests to perform which are listed below:")
113+
print("1. To perform the assertEqual the unit test on the above done mathematical operation.")
114+
print("2. To perform the assertTrue the unit test on the above done mathematical operation.")
115+
print("3. To perform the assertFalse the unit test on the above done mathematical operation.")
116+
117+
menu_choice_for_unitttest = input()
118+
menu_choice_for_unitttest = int(menu_choice_for_unitttest)
119+
120+
if menu_choice_for_unitttest == 1:
121+
print("Expected value for test to pass:")
122+
expected_value = int(input())
123+
run_the unit test.the unit test_for_assert_equals(result,expected_value)
124+
elif menu_choice_for_unitttest == 2:
125+
print("Expected value for test to pass:")
126+
expected_value = int(input())
127+
run_the unit test.the unit test_for_assert_true(result,expected_value)
128+
elif menu_choice_for_unitttest == 3:
129+
print("Expected value for test to pass:")
130+
expected_value = int(input())
131+
run_the unit test.the unit test_for_assert_false(result,expected_value)
132+
133+
134+
print("To go on with the code getting executed, enter input [y] or [n]")
135+
continue_or_exit = input()
136+
137+
if continue_or_exit == 'y' or continue_or_exit == 'Y':
138+
pass
139+
elif continue_or_exit == 'n' or continue_or_exit == 'N':
140+
sys.exit()
141+
142+
if __name__ == '__main__':
143+
main()

AUTOMATED_Software_Testing/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
**AUTOMATED Software testing**
2+
3+
4+
5+
**How to Use:**
6+
This Script is an AUTOMATED Software testing before that we need to import unittest , sys Then just we need to run AUTOMATED_Software_Testing.py simple and easy to use.
7+
8+
9+
**conclusion:**
10+
11+
This Just a Script That we can allow to AUTOMATE the Software testing from the terminal!
12+
13+
#### By [Kalivarapubindusree]()

0 commit comments

Comments
 (0)