India

ZestyBeanz Technologies Pvt Ltd Thejaswini, Technopark Thiruvananthapuram,
India – 695581
Phone: +91 471 4063254
Fax : +91 471 2700171

   .

ZestyBeanz Technologies Pvt Ltd, 2987, Manikkath Cross Road, Ravipuram, Kochi, India - 682016, Phone: +91 484 4063254

  UAE

ZestyBeanz Technologies FZE, P.O Box 53261, HFZA, Sharjah, Phone: +971-56-2708993​

  Germany​

ZestyBeanz Technologies UG Fürther Str. 27 90429 Nürnberg Phone: +49-911-28707070

How effective is YAML Testing in OpenERP?

Contact Form


Vinod_Kumar's picture

How effective is YAML Testing in OpenERP?

What is Yaml?

YAML is a human-readable data serialization format that takes concepts from programming languages such as C, Perl, and Python, and ideas from XML and the data format of electronic mail. YAML stands for YAML Ain’t Markup Language (yes, that’s a recursive acronym). YAML is available as a format for OpenERP data as of OpenERP 6.0, featuring the following advantages:
 
  •     User friendly format as an alternative to our current XML data format.
  •     Same system to load data or tests, integrated in modules.
  •     Built in OpenERP so that you can develop complex Python tests.
  •     Simpler for non developers to write functional tests.
How to write a Yaml Test?
This piece of information is written on the basis of the recent experience I had in writing YAML test for OpenERP. This mode of testing may be the best available approach to do automated tests in OpenERP which is really a major milestone during any enterprise implementation of this great application.
 
Writing a Yaml Test is a two phase process. In the first phase the person with a strong domain knowledge (need not be a developer) writes the required functional tests in plain English. In the second phase a developer converts these tests to codes.
The Test scenario is described for testing a wizard to create a Budget for a particular activity. It can be tried in any custom modules or functionalities. Some tests are already written in the existing OpenERP code and documentations are also available.  
 
A sample test case can be written by a non developer as follows:

  1. -
  2.     To test the budget creation wizard's working I create department, program, and activity and perform budget creation using these.
  3. -
  4.     I create a department named Test Department 1
  5. -
  6.     I create a program named Test Program 1 under Test Department 1
  7. -
  8.     I create an activity named Test Activity 1 under Test Program 1
  9. -
  10.     I select Test Department 1, Test Program 1, Test Activity 1 and 1991-1995 budget period
  11. -
  12.     I create a budget using the previously selected values.
  13. -
  14.     I test that the state of the budget is Draft.

Next a developer adds the actual code to perform these tests as follows:

  1. -
  2.     To test the budget creation wizard's working I create department, program, and activity and perform budget creation using these.
  3. -
  4.     I create a department named Test Department 1
  5. -
  6.     !record {model: zb.department, id: department_id_0}:
  7.         name: "Test Department 1"
  8. -
  9.     I create a program named Test Program 1 under Test Department 1
  10. -
  11.     !record {model: zb.program, id: program_id_0_0}:
  12.         name: "Test Program 1"
  13.         department_id: department_id_0
  14. -
  15.     I create an activity named Test Activity 1 under Test Program 1
  16. -
  17.     !record {model: zb.activity, id: activity_id_0_0_0}:
  18.         name: "Test Activity 1"
  19.         program_id: program_id_0_0
  20. -
  21.     I select Test Department 1, Test Program 1, Test Activity 1 and 1991-1995 budget period
  22. -
  23.     !record {model: zb.budget.target, id: budget_wizard_id}:
  24.         department_id: department_id_0
  25.         program_id: program_id_0_0
  26.         activity_id: activity_id_0_0_0
  27.         budget_period_id: budget_period_id_0
  28. -
  29.     I create a budget using the previously selected values.
  30. -
  31.     !python {model: zb.budget.target}: |
  32.         result = self.create_budget(cr, uid, [ref('budget_wizard_id')], {})
  33.         assert result, 'The budget was not created.'
  34. -
  35.     I test that the state of the budget is Draft.
  36. -
  37.     !python {model: zb.budget}: |
  38.         department_id = ref("department_id_0")
  39.         program_id = ref("program_id_0_0")
  40.         activity_id = ref("activity_id_0_0_0")
  41.         budget_period_id = ref("budget_period_id_0")
  42.         ids = self.search(cr, uid, [('department_id', '=', department_id), ('program_id', '=', program_id), ('activity_id', '=', activity_id), ('budget_period_id', '=', budget_period_id)])
  43.         assert len(ids) == 1, 'There should only be one budget for a combination of a particular department, program, activity and budget period.'
  44.         budget_obj = self.browse(cr, uid, ids, {})[0]
  45.         assert budget_obj.budget_state == 'draft', 'The newly created budget must be in Draft.'

 
Save this file with an extension .yml for example budget_creation_wizard.yml.
 
How to run the test?
In the __openerp__.py file add the name of the test file including its relative path in the test tag. That is,

  1. 'test' : ['test/budget_creation_wizard.yml']

 
Start the openerp server with the following parameter --log-level=test. This will log the details of the test being done. By looking at the log we can find which all tests were performed and which all tests passed and the failed tests.

  1. ./openerp-server.py --log-level=test

 
In the log file we can see lines like the following:

  1. TEST:tests.budget_performance:To test the budget creation wizard's working I create department, program, and activity and perform budget creation using these.
  2. TEST:tests.budget_performance:I create a department named Test Department 1.
  3. TEST:tests.budget_performance:I create a program named Test Program 1 under Test Department 1.
  4. TEST:tests.budget_performance:I create an activity named Test Activity 1 under Test Program 1.
  5. TEST:tests.budget_performance:I select Test Department 1, Test Program 1, Test Activity 1 and 1991-1995 budget period.
  6. TEST:tests.budget_performance:I create a budget using the previously selected values.
  7. TEST:tests.budget_performance:I test that the state of the budget is Draft.

 
Limitations of YAML Testing
Since YAML testing is a server side testing, there is a limitation in testing the view of the model. Eventhough we cannot test the view completely some features of the view that we can test includes:
 
  • When we change a particular field's value another field(s) depending on this field changes. This scenario can be simulated by writing a test which calls the onchange function in the corresponding model.
  • Check the view's rendering. Even though this test does not guarantee that the view will be rendered correctly but at least we can make sure that the view is not having any major error. This can be accomplished by writing a test that calls the fields_view_get function of the corresponding model.
  • Button click. The button click can be simulated by writing tests which calls the underlying function to which the button calls.
Conclusion
Yaml testing makes regression testing easy. With a fair amount of good tests we can be assured about the quality of the code and any modification of the existing features or addition of the new features does not introduce any new bug.
 
Some useful links
1. http://doc.openerp.com/v6.0/developer/5_16_data_serialization/
2. http://doc.openerp.com/v6.0/contribute/15_guidelines/coding_guidelines_testing.html
3. http://fptiny.blogspot.com/2010/09/new-automated-test-framework-for.html
4. http://fptiny.blogspot.com/2010/09/improved-automated-tests-for-openerp.html

Bista Solutions's picture

Hi, Thank You for the post

Hi,

Thank You for the post you posted regarding YML.But we are facing some issues while running the YML files in Opernerp 6.1.
We expect some results after running the YML files which will tell us the test cases result we provide in YML file.

Can you please explain us in detail how we can use YML to test our code and what output we expect after running YML in Openerp.

Do YML runs for a file or whole module?

Thanks

Timothy's picture

Yes, please help on how to

Yes, please help on how to check the results of the test. I tried running a test that fails but it doesnt show up on the log: http://stackoverflow.com/questions/14458962/how-do-you-run-openerp-yaml-...
I tried adding a test directory parameter but no luck :(