2018年9月6日(周四)

开发测试

单元测试
  • 测试风格
    • TDD 测试驱动开发
    • BDD 行为驱动开发 目前公司使用的
  • 测试框架
    • mocha
    • jest
  • 断言
    • power-assert
    • assert
性能测试
  • 基准测试
    • benchmark.js
  • 压力测试
    • ab 目前使用的是ab
    • siege
    • http_load
使用jest完成测试
npm i jest -D  安装jest包

在package.json文件中添加

  "scripts": {
    "test": "jest --coverage",// --coverage可以测试代码覆盖率
  },
   "jest": {
    "collectCoverage": true
  }

具体配置: Configuring JestJest CLI Options
在根目录下添加 test/demo.test.js并写入

'use strict';
describe('test demo', () => {
  it('should be demo', () => {
   // do somethings
  });

运行

npm run test

MongoDB增删改查

insert() // 返回值为
    WriteResult({ "nInserted" : 1 }) 
    或 
    BulkWriteResult({
        "writeErrors" : [ ],
        "writeConcernErrors" : [ ],
        "nInserted" : 2,
        "nUpserted" : 0,
        "nMatched" : 0,
        "nModified" : 0,
        "nRemoved" : 0,
        "upserted" : [ ]
    })

insertOne() // 返回值为
    {
        "acknowledged" : true,
        "insertedId" : ObjectId("5b9793ac05c674531bf5bafc")
    }

insertMany() // 返回值为
    {
        "acknowledged" : true,
        "insertedIds" : [
            ObjectId("5b9793e0b9b1bf5475b12ac5"),
            ObjectId("5b9793e0b9b1bf5475b12ac6")
        ]
    }
  • insertMany 和 insertOne区别:insertMany能插入多个而insertOne只能插入一个
  • insertMany 和 insert的区别:insert能插入一个或多个,且和insertMany返回值不同
deleteOne() //返回值为
    {
        "acknowledged" : true,
        "deletedCount" : 1
    }
deleteMany() //返回值为
    {
        "acknowledged" : true,
        "deletedCount" : 2
    }
updateOne(query, update, options) // 返回值为
    {
        "acknowledged" : true,
        "matchedCount" : 1,
        "modifiedCount" : 1
    }
updateMany(query, update, options) // 返回值为
    {
        "acknowledged" : true,
        "matchedCount" : 2,
        "modifiedCount" : 2
    }
replaceOne(query, update, options) //返回值为
    {
        "acknowledged" : true,
        "matchedCount" : 1,
        "modifiedCount" : 1
    }
update(query, update, options)
    WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
  • update 和 updateMany区别:update可以更新一个或多个,需要使用 options里添加{multi:true}
  • update 和 replaceOne区别:update不适用操作符的时,则和replaceOne一样为替换。使用操作符时,如$set,则为更新
find() // 数据list
findOne() // 数据list

在mongo shell中,当把find值赋给变量时,他不会自动迭代

var c = db.collection.find();
// 此时需要手动迭代游标 使用next()、forEach()或使用toArray()转换为数组来操作
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值