Scratch中的项目单元测试,很巧妙的思想。
1.大概流程

2.测试代码
const test = require('tap').test;
test('test fan open or close', t => {
const rt = new Runtime();
rt.addListener('remoteControlResponse', (type, ret) => {
t.strictEqual(ret,'exception');
t.end();
});
const looks = new Looks(rt);
const args = {OPEN_CLOSE: '1'};
looks.remotecontrol(args, util);
});Looks中的remotecontrol方法,等待异步ajax请求后触发监听函数。

本文介绍了Scratch项目中的一项单元测试实践,通过使用测试框架tap进行自动化测试。具体包括了测试代码的编写过程,利用异步监听机制验证Looks模块中的remotecontrol方法是否能正确响应远程控制指令。

1047

被折叠的 条评论
为什么被折叠?



