MongoDB快速上手指南: 使用 Mocha 编写测试 “Test Driven Development”

2022-08-0222:27:31数据库教程Comments1,127 views字数 956阅读模式

Mocha 是一个 js 测试的包, 编写测试有两个关键字 describeit文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/26462.html

  • describe 是一个”统领块”, 所有的 test functions 都会在它”名下”
  • it 表示每一个 test function
create_test.js
const assert = require('assert')
// assume we have a User model defined in src/user.js
const User = require('../src/user')

// after installing Mocha, we have global access
// to describe and it keywords
describe('Creating records', () => {
  it('saves a user', () => {
    const joe = new User({ name: "Joe" });
    joe.save();
    assert()
  });
});
复制代码

NoSQL Databases文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/26462.html

Benefits of NoSQL文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/26462.html

  • Easy for inserting and retrieving data, since they are contained in one block, in one json object
  • Flexible schema, if a new attribute added, it is easy to just add / append to the object
  • Scalability, horizontally partition the data (availability > consistency)
  • Aggregation, find metrics and etc

Drawbacks of NoSQL文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/26462.html

  • Update = Delete + Insert, not built for update
  • Not consistent, ACID is not guaranteed, do not support transactions
  • Not read optimized. Read entire block find the attribute. But SQL, just need one column (read time compartively slow)
  • Relations are not implicit
  • JOINS are hard to accomplish, all manually

作者:是小梁同学呀
来源:稀土掘金文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/26462.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/sjk/26462.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定