单元测试框架 gjstest

码农软件 · 软件分类 · 单元测试工具 · 2019-11-18 10:27:10

软件介绍

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));
});


本文地址:https://codercto.com/soft/d/19246.html

Effective JavaScript

Effective JavaScript

David Herman / Addison-Wesley Professional / 2012-12-6 / USD 39.99

"It's uncommon to have a programming language wonk who can speak in such comfortable and friendly language as David does. His walk through the syntax and semantics of JavaScript is both charming and h......一起来看看 《Effective JavaScript》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具