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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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:
Check Math and then click the Load Selected button.
Add test blocks for tests.
Click the XML button (next to Generate:) when you're done.
Copy this XML. This becomes your new XML for the math.xml file.
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).