Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you run OpenERP yaml unit tests

I'm trying to run unit tests on my openERP module, but no matter what I write it doesnt show if the test passes or fails! Anyone know how to output the results of a test? (Using Windows OpenERP version 6.1)

My YAML test is:

- 
  I test the tests
-
  !python {model: mymodelname}: |
    assert False, "Testing False!"
    assert True, "Testing True!"

The output when I reload the module with openerp-server.exe --update mymodule --log-level=test -dtestdb shows that the test ran but has no errors?!

... TEST testdb openerp.tools.yaml_import: I test the tests

What am I doing wrong?

Edit: ---------------------------------------------------------------------

Ok so after much fiddling with the !python, I tried out another test:

- 
    I test that the state
-
!assert {model: mymodel, id: mymodel_id}:
    - state == 'badstate'

Which gave the expected failure:

WARNING demo_61 openerp.tools.yaml_import: Assertion "NONAME" FAILED
test: state == 'badstate'
values: ! active == badstate

So I'm guessing it is something wrong with my syntax which may work as expected in version 7.

Thanks for everyone's answers and help!

like image 368
TimoSolo Avatar asked Jan 22 '13 12:01

TimoSolo


People also ask

How do you run a unit test?

To run all the tests in a default group, choose the Run icon and then choose the group on the menu. Select the individual tests that you want to run, open the right-click menu for a selected test and then choose Run Selected Tests (or press Ctrl + R, T).

How we can run the Qunit test cases in Odoo?

How To Run Test Cases? For running the tests, you have to use test_enable = True in your odoo-server. conf file. After it is enabled, tests will automatically run when you update or install the modules.

What is unit test file?

Unit tests are typically automated tests written and run by software developers to ensure that a section of an application (known as the "unit") meets its design and behaves as intended. In procedural programming, a unit could be an entire module, but it is more commonly an individual function or procedure.


1 Answers

This is what I've tried. It seems to work for me:

!python {model: sale.order}: |
    assert True, "Testing True!"
    assert False, "Testing False!"

(Maybe you forgot the "|" character)

And then :

bin/start_openerp --init=your_module_to_test -d your_testing_database --test-file=/absolute/path/to/your/testing_file.yml

You might want to create your testing database before :

createdb mytestdb --encoding=unicode

Hope it helps you

UPDATE: Here are my logs ( I called my test file sale_order_line_test.yml)

ERROR mytestdb openerp.tools.yaml_import: AssertionError in Python code : Testing False!
mytestdb openerp.modules.loading: At least one test failed when loading the modules.
loading test file /path/to/module/test/sale_order_line_test.yml
AssertionError in Python code : Testing False!
like image 70
nay Avatar answered Sep 23 '22 11:09

nay