I have come a long way with the project thanks in a large part to this and the Slack community. Once I get the piece fine-tuned, it seems I will need to run some tests on it in order to keep it up-to-date with the MakeCode software. Can anyone point me toward some resources to help me learn how to Unit Test for MakeBlock and the micro:bit?
What process do you all go through? Thank you.
I thought I would post an update for those interested.
Here are the answers to most of my Unit Test questions.
What platform/ extension do we use to test our extension?
A: Microsoft uses Github’s built-in test suite. You could use something else on the command line, but I currently do not see it as necessary.
How do we ensure our tests pass?
A: If you are using the online version of MakeCode combined with GitHub, this happens automatically. All you need to do is put your test code in test.ts, and the GitHub agent runs through the tests on build.
How do I know what to put in my test code?
Simply test all of your blocks as you feel they will be utilized.
My library relies upon hardware and other libraries, how is that going to work with Unit Testing?
It seems to work fine. I just put code in my test.ts file that mimicked how users would use it. It seems all libraries are accounted for (when a user installs your library, it pulls in dependencies automatically).
How do you handle different options and user logic?
I think this could get me deep into the weeds, so my plan is to use a state machine and run through the primary use cases ensuring all blocks are used effectively.
This is really cool. Thank you all for your help.
Thanks for sharing! Here are how I’m doing some unit testing:
- I use an
assert() function that tests return values of reporter blocks (function returns). It also totals the successes and failures. Fortunately, everything I’ve needed to test so far can be tested this way.
- I have a bunch of individual test cases that do a primitive setup and test. They report outcomes to
serial, which works well for how I test.
- I’m working from the command line / locally on all development). I usually run the tests (now on both v1 and v2) before I
Here’s my example tests for my time & date extension: https://github.com/bsiever/microbit-pxt-timeanddate/blob/master/test.ts