关于uniitest的官方使用文档,参考:https://docs.python.org/2/library/unittest.html html
Mac中python配置:java
因为java7在yosemite中出现各类问题,各位使用java6的孩童们仍是不要尝试使用eclipse + pydev,我本身的python开发环境就是Sublime Text2加上Python Auto-Complete,感受很能够,Pylinter安装之后貌似有些冲突,总是致使意外退出,也有多是我本身的环境问题,不作深刻研究了。直接使用command+b运行,结果在sublimeText2上就能够直接显示python
已有的测试函数:app
对于已经有的测试函数也是能够包含到uniitest测试框架中,例如:
框架
def singleasser(): assert value == 10 if __name__ == '__main__': testsingle = unittest.FunctionTestCase(singleasser) #unittest.main(verbosity=2) widgetTestSuite = unittest.TestSuite() widgetTestSuite.addTest(testsingle) value = 11 unittest.TextTestRunner(verbosity=0).run(widgetTestSuite)
对于测试结果的获取,例如:eclipse
results = unittest.TextTestRunner(verbosity=0).run(widgetTestSuite) if results.wasSuccessful() == True: print 'case wasSuccessful' else: print 'case failure'
上述results就是 unittest.TestResult函数
在调试过程当中,若是对于对象的属性不是很清楚,推荐使用dir来看下,例如:测试
print dir(results)
最后Happy New yearui