The JavaScript unit test in Odoo

Source: Internet
Author: User
Tags xpath

The front-end page uses Qunit for unit testing, this article refers to the official documentation: https://www.odoo.com/documentation/8.0/reference/javascript.html

Access the/web/tests page to see all current unit test lists that contain test modules.

The custom unit test method is as follows:

1. Add a reference to the JS file in the __openerp__ file:

(in the unofficial document to write the JS file in the ' test ', but reference the view file, in the view file to add a reference to JS, after 8.0 valid)

<TemplateID= "Assets_backend"name= "Qweb_test"inherit_id= "Web.qunit_suite">            <XPathExpr= "//head"position= "Inside">                <Scripttype= "Text/javascript"src= "/px_qweb/static/test/demo.js"></Script>            </XPath></Template>

2. Create JS file, write unit test

Unit tests take openerp.testing as namespaces, and tests are written in the section function.

Openerp.testing.section (' My.test ', function (test) {    Test (' My first Test ', function () {        OK} (False, "this test has Run ");});    

3. Assertions

Ok (State[,messsage]): Check if state is true

Strictequal (Actual,expected[,message]): Strictly Test for equality

Notstrictequal (Actual,expected[,message]): rigorously tested for unequal

Deepequal (Actual,expected[,message]): For object and array types, ensure that the key values for each element are equal

Notdeepequal (Actual,expected[,message]): Contrary to deepequal

Throws (Block[,expected][,messsage]): Block throws an exception to verify that the thrown exception is the same as expected (expected).

Equal (Actual,expected[,message]): Test for equality

NotEqual (Actual,expected[,message]): Contrary to equal

Example:

Custom data.js Files:

(function () {    Openerp.px_qweb =  {            value_true:true,            SomeType:openerp.web.Class.extend ({                init: function (value) {                    this.value = value;                }}            )        };} ());

Unit tests:

Openerp.testing.section (' px QWeb ', function (test) {    test (' px test ', function (instance) {        OK (instance.px_ Qweb.value_true, ' should has a true value ');        var type_instance = new Instance.px_qweb. SomeType (+);        Strictequal (type_instance.value,50, ' should has provided value. ');    });

The JavaScript unit test in Odoo

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.