# 对微服务Api的实践

## 资料

[Test-Driven-Development for building APIs in Node.js and Express](https://developers.redhat.com/blog/2016/03/15/test-driven-development-for-building-apis-in-node-js-and-express/)

说明：针对的express框架如何开展tdd的步骤。

* 指出从如何从功能测试(集成测试)，引出单元测试（function函数测试）
* 示例代码：<https://github.com/cianclarke/tdd-for-apis>

[Testing Node and Express](https://mherman.org/blog/testing-node-and-express/)

说明：使用express的crud操作阐述tdd过程。

* 同样提到了功能测试(集成测试)和单元测试（function函数测试）
* 提出了一个很好的解决测试数据的问题,自动生成：[faker.js](https://github.com/marak/Faker.js/)
* 示例代码：<https://github.com/mjhea0/express-testing-mocha-knex>

[Test Driven Development with Node, Postgres, and Knex (Red/Green/Refactor)](https://mherman.org/blog/test-driven-development-with-node/)

说明：详细使用Red/Green/Refactor的原则的crud操作阐述tdd过程。

* 字段全校验
* 示例代码：<https://github.com/mjhea0/mocha-chai-knex>

## 其他参考：

[BDD/TDD development from scratch with node.js/express](https://www.robotlovesyou.com/bdd-tdd/)

[Building Node.js REST API with Express.js, MongoDB & TDD – Tutorial](https://www.novicedeveloper.com/building-nodejs-rest-api-expressjs-mongodb-tdd/)

[TDD: Testing NodeJS and React with Mocha, Chai, Sinon and Enzyme](http://www.darrenbeck.co.uk/react/testing/testing-part1/)

[ Node Express TDD with RESTful API in Intellij](http://www.whiteboardcoder.com/2015/04/node-express-tdd-with-restful-api-in.html)

[Test-driven Development of Node.js APIs](https://www.sphereinc.com/test-driven-development-of-node-js-apis/)

[Express Routes: A TDD Approach](https://medium.com/@jodylecompte/express-routes-a-tdd-approach-1e12a0799352)

[Using Test-Driven Development for Microservices](https://nordicapis.com/using-test-driven-development-for-microservices/)　（Lex）

![](/files/-LgejdsVRFn8dja7RfdT)

![](/files/-LgekkjU0QrIhdSjw31t)

![](/files/-LgekQbYkJK4-e4dRx92)

![](/files/-LgekFiE_xP9bHuuVijH)

![](/files/-Lgek1rO0i3toOrMV9pj)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tdd.shujuwajue.com/ju-ti-shi-jian-1/dui-wei-fu-wu-api-de-shi-jian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
