Skip to content

mrozenbaum/calculator-unit-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Calculator Unit Tests

Just like you did in JavaScript when you learned about Jasmine, you're going to create a class that test the functionality of a Calculator class.

Starter code for test class

Note: The setUpClass method below must have the @classmethod decorator above it. import unittest import calculator

def setUpModule(): print('set up module')

def tearDownModule(): print('tear down module')

class TestCalculator(unittest.TestCase):

@classmethod def setUpClass(self): print('Set up class') # Create an instance of the calculator that can be used in all tests

@classmethod def tearDownClass(self): print('Tear down class')

def test_add(self): self.assertEqual(self.calc.add(2, 7), 9)

Write test methods for subtract, multiply, and divide

if name == 'main': unittest.main() Starter code for calculator class

class Calculator(): """Performs the four basic mathematical operations

Methods:
 add(number, number)
 subtract(number, number)
 multiply(number, number)
 divide(number,number)
"""

def add(self, firstOperand, secondOperand):
    """Adds two numbers together

    Arguments:
      firstOperand - Any number
      secondOperand - An number
    """

    return firstOperand + secondOperand

Running the test class

python CalcTest.py -v

About

Unit testing practice in Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages