Python+Selenium练习篇之6--断言(1)

论坛 期权论坛     
选择匿名的用户   2021-5-30 02:00   130   0
<p>转载:<a href="https://www.cnblogs.com/yufeihlf/p/5707929.html#test2">https://www.cnblogs.com/yufeihlf/p/5707929.html#test2</a></p>
<p><span style="color:#3399ea;"><strong>一、unittest模块各个属性说明</strong></span></p>
<p><span style="color:#f33b45;"><u><strong>1.unittest的属性如下:</strong></u></span></p>
<p>[&#39;BaseTestSuite&#39;, &#39;FunctionTestCase&#39;, &#39;SkipTest&#39;, &#39;TestCase&#39;, &#39;TestLoader&#39;, &#39;TestProgram&#39;, &#39;TestResult&#39;, &#39;TestSuite&#39;, &#39;TextTestResult&#39;, &#39;TextTestRunner&#39;, &#39;_TextTestResult&#39;, &#39;__all__&#39;, &#39;__builtins__&#39;, &#39;__doc__&#39;, &#39;__file__&#39;, &#39;__name__&#39;, &#39;__package__&#39;, &#39;__path__&#39;, &#39;__unittest&#39;, &#39;case&#39;, &#39;defaultTestLoader&#39;, &#39;expectedFailure&#39;, &#39;findTestCases&#39;, &#39;getTestCaseNames&#39;, &#39;installHandler&#39;, &#39;loader&#39;, &#39;main&#39;, &#39;makeSuite&#39;, &#39;registerResult&#39;, &#39;removeHandler&#39;, &#39;removeResult&#39;, &#39;result&#39;, &#39;runner&#39;, &#39;signals&#39;, &#39;skip&#39;, &#39;skipIf&#39;, &#39;skipUnless&#39;, &#39;suite&#39;, &#39;util&#39;]</p>
<p>说明:</p>
<p><span style="color:#e579b6;"><u><strong>unittest.TestCase</strong></u></span>:TestCase类,所有测试用例类继承的基本类。</p>
<pre class="blockcode">class BaiduTest(unittest.TestCase):</pre>
<p><span style="color:#e579b6;"><u><strong>unittest.main()</strong></u></span>:使用她可以方便的将一个单元测试模块变为可直接运行的测试脚本,main() 方法使用TestLoader类来搜索所有包含在该模块中以“test”命名开头的测试方法,并自动执行他们。执行方法的默认顺序是:根据ASCII码的 顺序加载测试用例,数字与字母的顺序为:0-9,A-Z,a-z。所以以A开头的测试用例方法会优先执行,以a开头会后执行。</p>
<p><span style="color:#e579b6;"><u><strong>unittest.TestSuite()</strong></u></span>:unittest框架的TestSuite()类是用来创建测试套件的。</p>
<p><u><span style="color:#e579b6;"><strong>unittest.TextTextRunner()</strong></span></u>:unittest框架的TextTextRunner()类,通过该类下面的run()方法来运行suite所组装的测试用例,入参为suite测试套件。</p>
<p><span style="color:#e579b6;"><u><strong>unittest.defaultTestLoader()</strong></u></span>: defaultTestLoader()类,通 过该类下面的discover()方法可自动更具测试目录start_dir匹配查找测试用例文件(test*.py),并将查找到的测试用例组装到测试 套件,因此可以直接通过run()方法执行discover。用法如下:</p>
<pre class="blockcode">discover&#61;unittest.defaultTestLoader.discover(test_dir, pattern&#61;&#39;test_*.py&#39;)</pre>
<p><span style="color:#e579b6;"><u><strong>unittest.skip()</strong></u></span>:装饰器,当运行用例时,有些用例可能不想执行等,可用装饰器暂时屏蔽该条测试用例。一种常见的用法就是比如说想调试某一个测试用例,想先屏蔽其他用例就可以用装饰器屏蔽。</p>
<p>&#64;unittest.skip(reason): skip(reason)装饰器:无条件跳过装饰的测试,并说明跳过测试的原因。</p>
<p>&#64;unittest.skipIf(reason): skipIf(condition,reason)装饰器:条件为真时,跳过装饰的测试,并说明跳过测试的原因。</p>
<p>&#64;unittest.skipUnless(reason): skipUnless(condition,reason)装饰器:条件为假时,跳过装饰的测试,并说明跳过测试的原因。</p>
<p>&#64;unittest.expectedFailure(): expectedFailure()测试标记为失败。</p>
<p><span style="color:#f33b45;"><u><strong>2.TestCase类的属性如下:</strong></u></span></p>
<p>[&#39;__call__&#39;, &#39;__class__&#39;, &#39;__delattr__&#39;, &#39;__dict__&#39;, &#39;__doc__&#39;, &#39;__eq__&#39;, &#39;__format__&#39;, &#39;__getattribute__&#39;, &#39;__hash__&#39;, &#39;__init__&#39;, &#39;__module__&#39;, &#39;__ne__&#39;, &#39;__new__&#39;, &#39;__reduce__&#39;, &#39;__reduce_ex__&#39;, &#39;__repr__&#39;, &#39;__setattr__&#39;, &#39;__sizeof__&#39;, &#39;__str__&#39;, &#39;__subclasshook__&#39;, &#39;__weakref__&#39;, &#39;_addSkip&#39;, &#39;_baseAssertEqual&#39;, &#39;_classSetupFailed&#39;, &#39;_deprecate&#39;, &#39;_diffThreshold&#39;, &#39;_formatMessage&#39;, &#39;_getAssertEqualityFunc&#39;, &#39;_truncateMessage&#39;, &#39;addCleanup&#39;, &#39;addTypeEqualityFunc&#39;, &#39;assertAlmostEqual&#39;, &#39;assertAlmostEquals&#39;, &#39;assertDictContainsSubset&#39;, &#39;assertDictEqual&#39;, &#39;assertEqual&#39;, &#39;assertEquals&#39;, &#39;assertFalse&#39;, &#39;assertGreater&#39;, &#39;assertGreaterEqual&#39;, &#39;assertIn&#39;, &#39;assertIs&#39;, &#39;assertIsInstance&#39;, &#39;assertIsNone&#39;, &#39;assertIsNot&#39;, &#39;assertIsNotNone&#39;, &#39;assertItemsEqual&#39;, &#39;assertLess&#39;, &#39;assertLessEqual&#39;, &#39;assertListEqual&#39;, &#39;assertMultiLineEqual&#39;, &#39;assertNotAlmostEqual&#39;, &#39;assertNotAlmostEquals&#39;, &#39;assertNotEqual&#39;, &#39;assertNotEquals&#39;, &#39;assertNotIn&#39;, &#39;assertNotIsInstance&#39;, &#39;assertNotRegexpMatches&#39;, &#39;assertRaises&#39;, &#39;assertRaisesRegexp&#39;, &#
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP