gjstest- 单元测试框架

网友投稿 803 2022-10-17

gjstest- 单元测试框架

gjstest- 单元测试框架

gjstest(Google JS Test)是在 V8 引擎上快速运行 javascript单元测试框架的工具,且不需要用户启动完整的浏览器。当然,假如你在 V8 上面测试的时候没有浏览器也没有 DOM 的话,你可以使用本工具来完成测试。

特征如下:

能够极快的启动测试和执行测试,且不需要运行浏览器输出可读的测试结果,测试失败也可读、明了一个基于浏览器的测试运行工具能够随 JS 的变化而变化风格和语义都类似 C++风格内置模拟框架,所以只需要极少的代码即可完成测试

代码示例:

function UserInfoTest() {  // Each test function gets its own instance of UserInfoTest, so tests can  // use instance variables to store state that doesn't affect other tests.  // There's no need to write a tearDown method, unless you modify global  // state.  //  // Create an instance of the class under test here, giving it a mock  // function that we also keep a reference to below.  this.getInfoFromDb_ = createMockFunction();  this.userInfo_ = new UserInfo(this.getInfoFromDb_);}registerTestSuite(UserInfoTest);addTest(UserInfoTest, function formatsUSPhoneNumber() {  // Expect a call to the database function with the argument 0xdeadbeef. When  // the call is received, return the supplied string.  expectCall(this.getInfoFromDb_)(0xdeadbeef)    .willOnce(returnWith('phone_number: "650 253 0000"'));  // Make sure that our class returns correctly formatted output.  expectEq('(650) 253-0000', this.userInfo_.getPhoneForId(0xdeadbeef));});addTest(UserInfoTest, function returnsLastNameFirst() {  expectCall(this.getInfoFromDb_)(0xdeadbeef)    .willOnce(returnWith('given_name: "John" family_name: "Doe"'));  // Make sure that our class puts the last name first.  expectEq('Doe, John', this.userInfo_.getNameForId(0xdeadbeef));});

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Problem A: 还会用继承吗?
下一篇:Codeforces 1130 Connect——水题
相关文章

 发表评论

暂时没有评论,来抢沙发吧~