-1

I need to generate unit tests for a mathematical equation such as a= (b+c)* d and boolean expressions.Is there any methodology and/or utility to achieve this?

1 Answers1

1

Note:

Because of the vagueness of the question i'm going to assume the programming language one can use is variable. In this case Python uses a object oriented approach to unittesting.

Answer:

For most unittest problems in python, you can use the standard unittest library. An example case for the given equation can be:

import unittest

def test_equation(b,c,d):
    return (b+c) * d

class testEquation(unittest.TestCase):

    def setUp(self):
        pass

    def testEquationInput(self):
        b = 5
        c = 4
        d = 10
        self.assertEqual(test_equation(b,c,d), 90)

if __name__ == "__main__":
    unittest.main()

you can execute this code with:

python unittest test_module.py

or if you write a directory with unittests:

python -m unittest discover /path/to/test/directory