利用blockly源码测试块生成

Unit Tests

After changing or adding code, you should run existing unit tests and consider writing more. All tests are executed on the uncompressed versions of the code.

There are two sets of unit tests: JS tests and block generator tests.

JS Tests

The JS tests confirm the operation of internal JavaScript functions in Blockly's core. Running these is trivial, just load tests/jsunit/index.html in a browser. All tests should pass.

Block Generator Tests

Each block has its own unit tests. These tests verify that blocks generate code than functions as intended.

  1. Load tests/generators/index.html in Firefox or Safari. Note that Chrome and Opera have security restrictions that prevent loading the tests from the local "file://" system (Issues 41024 and 47416).
  2. Choose the relevant part of the system to test from the drop-down menu, and click "Load". Blocks should appear in the workspace.
  3. Click on "JavaScript".
    Copy and run the generated code in a JavaScript console. If the output ends with "OK", the test has passed.
  4. Click on "Python".
    Copy and run the generated code in a Python interpreter. If the output ends with "OK", the test has passed.
  5. Click on "PHP".
    Copy and run the generated code in a PHP interpreter. If the output ends with "OK", the test has passed.
  6. Click on "Lua".
    Copy and run the generated code in a Lua interpreter. If the output ends with "OK", the test has passed.
  7. Click on "Dart".
    Copy and run the generated code in a Dart interpreter. If the output ends with "OK", the test has passed.

Editing Block Generator Tests

  1. Load tests/generators/index.html in a browser.
  2. Choose the relevant part of the system from the drop-down menu, and click "Load". Blocks should appear in the workspace.
  3. Make any changes or additions to the blocks.
  4. Click on "XML".
  5. Copy the generated XML into the appropriate file in tests/generators/.

你可能感兴趣的:(blockly)