0% found this document useful (0 votes)
3 views3 pages

Nirajj 1

The document outlines an experiment conducted by student Niraj Kumar on writing a test script for basic arithmetic operations using a unit testing framework. It includes the aim, objectives, required materials, and a sample code implementing addition, subtraction, multiplication, and division functions along with their respective test cases. The conclusion emphasizes recording test results and verifying the correctness of operations, particularly handling edge cases like division by zero.

Uploaded by

skshivam3940
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Nirajj 1

The document outlines an experiment conducted by student Niraj Kumar on writing a test script for basic arithmetic operations using a unit testing framework. It includes the aim, objectives, required materials, and a sample code implementing addition, subtraction, multiplication, and division functions along with their respective test cases. The conclusion emphasizes recording test results and verifying the correctness of operations, particularly handling edge cases like division by zero.

Uploaded by

skshivam3940
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment 2

Student Name: Niraj Kumar​ UID: 24MCI10252


Branch: MCA(AIML)​ Section/Group: MAM3B
Semester: 2nd sem​ SubjectCode: 24CAH-654
Subject Name: Software Testing

1.​Aim and Overview:

To write a test script using a unit testing framework for addition, subtraction, multiplication, and
division of two numbers.

Objective

●​ To understand the fundamentals of unit testing.


●​ To create a test script for arithmetic operations using a unit testing framework.
●​ To validate the correctness of basic mathematical operations.

Materials Required

●​ Computer with an integrated development environment (IDE) installed.


●​ Access to documentation or resources on the chosen unit testing framework.

import unittest

def add(a, b):

return a + b

def subtract(a, b):

return a - b

def multiply(a, b):

return a * b

def divide(a, b):


if b == 0:

raise ValueError("Cannot divide by zero")

return a / b

class TestArithmeticOperations(unittest.TestCase):

def test_add(self):

self.assertEqual(add(2, 3), 5)

self.assertEqual(add(-1, 1), 0)

def test_subtract(self):

self.assertEqual(subtract(5, 3), 2)

self.assertEqual(subtract(0, 5), -5)

def test_multiply(self):

self.assertEqual(multiply(3, 4), 12)

self.assertEqual(multiply(-2, 3), -6)

def test_divide(self):

self.assertEqual(divide(6, 3), 2)

with self.assertRaises(ValueError):

divide(6, 0)

if __name__ == '__main__':

unittest.main()
Observations

●​ Record the results of the test cases.


●​ Note any errors or exceptions that occur during testing.
●​ Verify whether edge cases like division by zero are handled correctly.

Conclusion

●​ Summarize the results of the experiment. State whether all test cases passed and if the arithmetic
functions behaved as expected.

You might also like