I have been using IronPython lately, and am having a good time testing code with its built-in unit test framework. Here is a brief example of how to write some unit tests for IronPython (or CPython if that's your flavor). These unit tests leverage the "unittest" module available in Python 2.2 and above.
Here is a short test class:
class TestCode: localInt = 1 @classmethod def Method1(self): return 100 def Method2(self, a, b): self.localInt = a * b
Here are some sample unit tests for it, using the unittest framework:
import unittestclass UnitTests(unittest.TestCase): def testMethod1(self): cut = TestCode() actual = cut.Method1() self.assertEqual(100, actual)
def teststaticInt(self): self.assertEqual(1, TestCode.localInt)
def testMethod2(self): cut = TestCode() cut.Method2(7, 4) self.assertEqual(28, cut.localInt)
if __name__ == '__main__': unittest.main()
This example should illustrate that we can write some unit tests for our Python code fairly easily and quickly. It's nice to have a built-in framework for unit testing. There is also a "doctest" module available for doing more like system testing. I am pretty new to Python, so I haven't got examples of this as yet.
If anyone has any suggestions on tools or experience with integration with Visual Studio those comments would be appreciated.