乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Odoo測(cè)試 | Haiwei Liu 的博客

       gastonfeng 2016-04-08

      Odoo的模塊測(cè)試是基于unittest

      簡(jiǎn)要介紹

      編寫(xiě)測(cè)試程序,僅需要在模塊里定義tests子模塊,在測(cè)試的時(shí)候會(huì)自動(dòng)識(shí)別的。測(cè)試的py文件需要以test_開(kāi)頭而且需要導(dǎo)入到tests/__init__.py

      your_module
      |-- ...
      `-- tests
      |-- __init__.py
      |-- test_bar.py
      `-- test_foo.py

      __init__.py包含

      from . import test_foo, test_bar

      沒(méi)有從tests/__init__.py導(dǎo)入的測(cè)試模塊將不會(huì)運(yùn)行

      測(cè)試模塊的寫(xiě)法和一般的unittest文檔里一樣。但Odoo給模塊測(cè)試提供了一些基類(lèi)和函數(shù):

      • class openerp.tests.common.TransactionCase(methodName='runTest')
      • 每一個(gè)測(cè)試函數(shù)運(yùn)行在各自的事務(wù)里,有各自的游標(biāo)。函數(shù)執(zhí)行完畢后事務(wù)會(huì)回滾,游標(biāo)會(huì)關(guān)閉。

        • browse_ref(xid)
        • 根據(jù)外部標(biāo)志返回記錄對(duì)象
        • ref(xid)
        • 根據(jù)外部標(biāo)志返回?cái)?shù)據(jù)庫(kù)ID
      • class openerp.tests.common.SingleTransactionCase(methodName='runTest')

      • 所有的測(cè)試函數(shù)運(yùn)行在一個(gè)事務(wù)里,該事務(wù)會(huì)在第一個(gè)函數(shù)開(kāi)始,在最后一個(gè)執(zhí)行完畢后回滾。
        • browse_ref(xid)
        • 根據(jù)外部標(biāo)志返回記錄對(duì)象
        • ref(xid)
        • 根據(jù)外部標(biāo)志返回?cái)?shù)據(jù)庫(kù)ID

      默認(rèn)是模塊在安裝完畢后測(cè)試會(huì)運(yùn)行。測(cè)試也可以在設(shè)置為在所有模塊安裝后執(zhí)行:

      • openerp.tests.common.at_install(flag)
      • 設(shè)置at-install測(cè)試狀態(tài),用于是否運(yùn)行在模塊安裝的時(shí)候。默認(rèn)測(cè)試會(huì)在該模塊安裝后,下一個(gè)模塊安裝前運(yùn)行。
      • openerp.tests.common.post_install(flag)
      • 設(shè)置post-install測(cè)試狀態(tài),用于是否運(yùn)行在一系列模塊安裝后。默認(rèn)測(cè)試不會(huì)在當(dāng)前安裝的模塊集后運(yùn)行。

      最常見(jiàn)的案例就是使用TransactionCase,并在方法里測(cè)試模塊的一些屬性

      class TestModelA(common.TransactionCase):
      def test_some_action(self):
      record = self.env['model.a'].create({'field': 'value'})
      record.some_action()
      self.assertEqual(
      record.field,
      expected_field_value)

      # other tests...

      運(yùn)行測(cè)試

      如果在啟動(dòng)Odoo服務(wù)器時(shí)設(shè)置了--test-enable,測(cè)試會(huì)在安裝和更新模塊后自動(dòng)運(yùn)行。

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶(hù) 評(píng)論公約

        類(lèi)似文章 更多