Blockly Unit Testing issues

59 views
Skip to first unread message

Jeremy Jacob

unread,
Nov 19, 2021, 1:24:34 AM11/19/21
to Blockly
How to reproduce:
1. Open blockly playground (we used test block however, I don't think it's relevant because we didn’t use anything in it)
2. Copy all code from https://github.com/google/blockly/blob/develop/tests/generators/unittest.js into the developer console.
3. Copy all code from https://github.com/google/blockly/blob/develop/tests/generators/math.xml to the playground text area, then import from XML
4. Add a new unit test block.
5. Go to https://github.com/google/blockly/blob/develop/tests/generators/golden/generated.js then add the generated code (assertEquals) from the new unit test block in the corresponding place in that golden file (repeat for other languages).

Is there a way we can add unit tests in an easier way? This method seems pretty tedious to do. Thanks!

Jason Schanker

unread,
Nov 19, 2021, 12:48:15 PM11/19/21
to Blockly
Hi,

There is a Blockly Generator testing playground for this, which you can access here: https://google.github.io/blockly/tests/generators/.  If you want to add a test to math.xml, you can do the following:
  1. Check Math and then click the Load Selected button.  
  2. Add test blocks for tests.
  3. Click the XML button (next to Generate:) when you're done.  
  4. Copy this XML.  This becomes your new XML for the math.xml file.
  5. Click the JavaScript button.  Copy the lines starting with // Tests the "single block" and ending with the line before unittestResults = []; over the corresponding lines in generated.js.  (Since generated.js consists of a merging of the tests for all types of blocks, you won't want to include something shared like an assertEquals function definition as there will be code from other test types in between the function definition and the math tests here.)  You can repeat for the other languages (Dart => generated.dart, Lua => generated.lua, PHP => generated.php, Python => generated.py)
One caveat is that I think the link I provided is currently for the master branch.  To add tests for contributing purposes, you'll want to work off the develop branch.  (You can work locally or fork the Blockly repository and publish it off your develop branch on GitHub Pages.  Loading the file directly from https://raw.githubusercontent.com/google/blockly/develop/tests/generators/math.xml won't work on the playground because Cross-Origin Requests will be blocked (different domains of githubusercontent.com and github.io).


Best,
Jason

Reply all
Reply to author
Forward
0 new messages