单元测试框架 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

同伦方法纵横谈

同伦方法纵横谈

王则柯 / 大连理工大学 / 2011-5 / 25.00元

《走向数学丛书07-同伦方法纵横谈》,在本书里读者会看到许多人物故事,作为一本普及读物,我们有时候甚至觉得,对于不少读者来说,书中所写的科学研究中的人物故事,可能比书中介绍的具体的研究成果更有价值,这些人物故事,许多都出自我们个人之间的交往,这是从一个侧面了解科学研究的规律,了解科学家之成为科学家的珍贵记录。一起来看看 《同伦方法纵横谈》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具