3 YAML 自动测试指南

注解

Please see also section YAML 数据序列化

This is a guideline for project managers and developers on automated tests.

3.1 语法

Write scenarios using the YAML syntax, not the “cucumber” syntax, so that we can directly integrate these tests in OpenERP modules (and implement them later).

3.2 运行在服务端的测试

As tests are performed server side, you don’t need to write things like

  1. # wrong
  2. * Given I am logged in as admin user with proper password
  3. * module pos is installed

The user is admin by default, so no need to write this in each test file. And rather than saying ‘I check that the module pos is installed’, just write the name of the module where you will put this test. The first line would then be “module: pos”.

3.3 精确的测试目标

Try to use functional terms instead of object

  • This is not good enough:

    1. I will test the manufacturing order
  • An example of a good introduction:

    1. In order to test the CRM in OpenERP, I will do a customer qualification
    2. process that starts with a fist contact with a customer(a lead),
    3. which will be converted to a business opportunity and a partner.
  1. # wrong
  2. *In caldav testing of creation of calendar as Admin
  3. # better
  4. *In order to test the calendar synchronisation with mobile phones and
  5. outlook, I will test the caldav interface for meetings.
  6. # wrong:
  7. In order to test the manufacturing order process and modules As an
  8. administrator I want to see if the features work correctly.
  9. # better:
  10. In order to test the manufacturing of products, I will test the
  11. features of the manufacturing order document: consume raw materials,
  12. produce finished goods, scrap some products and split in production
  13. lots.
  14. # wrong:
  15. Testing of Document for ftp server is running and being connected or
  16. not
  17. # better:
  18. In order to test the document management system, I will try different
  19. operation on the FTP interface, and check their impacts on OpenERP's
  20. documents.

3.4 尽量避免依赖那些会被用户修改的数据

  1. # wrong (mrp):
  2. Then My manufacturing order turned into 'Waiting for goods' state.
  3. And one picking was also generated for my manufacturing order:
  4. 'INT/00001'.

This is not a good test, who know if it will be ‘INT/0001’ or another sequence ‘INT/0002’ ? Because the user may have created internal pickings before having installed the mrp module.

  1. # wrong (pos):
  2. I press new record from toolbar.
  3. Some default values are filled automatically like:
  4. Company>Tinysprl,Journal>x Sales Journal

You can not test if the company is ‘Tiny SPRL’. The user may have configured it to his own company name. It’s better to test: “The company is set by default to the company of the admin user.”

Take care of these data dependencies, because it may crash the tests simply because the user changed some demo data before launching the tests.

You can rely on demo data defined by the module where you put your test file, but if the demo data are defined by another module, try to either create your own data or find the way to work with ids instead of names.

3.5 把测试信息写得详细有助于Yaml测试系统进行测试

For example, the mail gateway. You can not write this:

  1. First I have made one fetchmail rc script using the proper syntax
  2. with specific email server and address information and used crm.lead
  3. as model Then I run the fetchmail command like: fetchmail -f <created
  4. rc file name> The script should exit successfully

Because you can not set-up an email pop account to test this.

I would rather do:

  1. I have a list of different emails with different encoding and
  2. different kind of attachments stored in the directory test/emails.
  3. I test to pass all these documents through the mailgateway script:
  4. something like:
  5. for each email file:
  6. call the script with stdin<this email file

If possible call in python directly, not using os.system.

For the FTP, it can be tested by the YAML as you simply have to use the Python FTP client in your yaml code:

  1. import ftplib

3.6 避免依赖现有的数据以防用户修改它们

Bad example:

When I pressed ‘Confirm Production’ button. Then I could see the Finished Products into Products to Consume with quantity 10.00.

Then My manufacturing order turned into ‘Waiting for goods’ state. And one picking was also generated for my manufacturing order: ‘INT/00001’.

And the following values appeared in the Products to Consume

product_id

product_qty

product_uom

location_id

||

||

[CPU_GEN] Regular processor config

10.00

PCE

库存

||

||

[HDD1] HDD Seagate 7200.8 80GB

10.00

PCE

库存

||

||

[TOW1] ATX Mid-size Tower

10.00

PCE

库存

||

||

[MOU] Mouse

10.00

PCE

库存

||

||

[KEYA] Keyboard -AZERTY

10.00

PCE

库存

||

||

For such an example, I would have created a few products and a bom in the test scenario. And test the manufacturing order on these test data.

3.7 不用深究测试的具体出错信息

Then I got the following error message:

xmlrpclib.Fault: <Fault warning — Error:

  1. Couldn't find bill of material for product: 'Traceback (most recent call last):
  2. File in dispatch
  3. result = ExportService.getService(service_name).dispatch(method, auth, params)
  4. File "/home/uco/workspace/Trunk/openobject-server/bin/service/web_services.py", line 587, in dispatch
  5. res = fn(db, uid, *params)
  6. File "/home/uco/workspace/Trunk/openobject-server/bin/osv/osv.py", line 64, in wrapper
  7. self.abortResponse(1, inst.name, inst.exc_type, inst.value)
  8. File "/home/uco/workspace/Trunk/openobject-server/bin/netsvc.py", line 66, in abortResponse
  9. raise Exception("%s -- %s\\n\\n%s"%(origin, description, details))
  10. Exception: warning -- Error
  11. Couldn\'t find bill of material for product\n'>
  12. Simply do::
  13. And it should generate an exception to say that he do not find a BoM
  14. defined for this product.

3.8 说明用户要做什么比在哪里点击要好

  1. # wrong:
  2. I press new record from toolbar of lead's view
  3. Some default values are filled automatically like: priority>Normal,user_id>Administrator, state>Draft
  4. Then I give some values for lead:
  5. |name|section_id|partner_name|phone|mobile|
  6. |Carrie Helle|Sales Department|Stonage IT|(855) 924-4364|(333) 715-1450|
  7. Then I press the save button from toolbar
  8. The lead is created successfully

No need to write the all the data of the form in the English text (phone, mobile, …). These data will be written in the final YAML, when you implement the test. A better final YAML for the above example should look like this:

  1. -
  2. As I met a new customer in a fair, I create a new lead "Stonage IT"
  3. to record his data.
  4. -
  5. !record {model:rcrm.lead, id:partner_carrie}
  6. name: Stonage IT
  7. contact_name: Carrie Helle
  8. phone: (855) 924-4364
  9. mobile: (333) 715-1450
  10. -
  11. I check that the state field is set automatically by default.
  12. -
  13. !assert {model:crm.lead, id:partner_carrie} state

3.9 你可以在测试里使用”onchange”以此来模拟客户端

  • I create a new sale order by filling the partner. I want addresses to be filled up by the onchange call but I still need to provide dummy addresses (required fields) to allow the record to be created.

  • !record {model: sale.order, id: my_order}:

    partner_id: base.res_partner_asus pricelist_id: product.list0 partner_order_id: base.main_address partner_invoice_id: base.main_address partner_shipping_id: base.main_address

  • I then call the onchange method and update the record with the returned value.

  • !python {model: sale.order}: |

    my_order = self.browse(cr, uid, ref(‘my_order’)) value = my_order.onchange_partner_id(my_order[‘partner_id’]).get(‘value’, {}) my_order.write(value)