2014年4月20日 星期日

008 unittest in python

  寫扣不寫單元測試,感覺就像炒菜不加鹽,不是大問題,只是怪怪的。

  Let's have a try with unittest in python. There are threes examples mentioned below, one is for "__name__", another is by "import unittest", and the other is reserved for someone who would like to customize his/her unittest via command line.


unit tests with __name__

  • We create a library module of tools and it also acts an executable program with self-test



unit test with unittest


  • We create another python script with suffix "_test", module_test.py
if __name__ == '__main__':
  unittest.main(verbosity=3)
  • reference
    • https://docs.python.org/2.6/library/unittest.html



unit test with unittest and customized command line


  • I want something like "--gtest_list_tests".


SUT

  • https://github.com/vash-hsu/python/blob/master/python_test/module.py

Test Code

  • https://github.com/vash-hsu/python/blob/master/python_test/module_test.py

沒有留言:

張貼留言