Node.js测试RESTful API(vows.js?) [英] Node.js testing RESTful API (vows.js?)
问题描述
我真的可以提供一些有关测试我在node.js中创建的RESTful api的建议.那里有很多框架,我很茫然.我的测试知识通常不够好,这就是为什么我要编写这些测试的原因.我尝试了vows.js,这看起来不错,但是我无法弄清楚如何整合我的API的测试,我需要某种客户端.我需要做的只是一个简单的示例来测试登录系统.
I could really do with some advice on testing a RESTful api I created in node.js. There are a plethora of frameworks out there and I am at a loss. My testing knowledge isn't good enough generally which is why I am trying to write these tests. I've tried vows.js which seems nice but I couldn't work out how to incorporate the testing of my API, I need some sort of client. An example of a simple post to test a login system is all I need to get going.
推荐答案
6个月后更新
发誓-很烂.使用摩卡
已更新为 vow-is 代码
Updated with vow-is code
这是 vows-是示例文件夹.
// simple HTTP
// Run with node example/simple-http.js
var express = require("express");
is = require("../src/vows-is.js");
is.config({
"server": {
"factory": function _factory(cb) {
var app = express.createServer();
app.get("/", function(req, res) {
res.send("hello world");
})
app.listen(3000);
cb(app);
},
"uri": "http://localhost:3000",
"kill": function _kill(app) {
app.close();
}
}
});
is.suite("http request test").batch()
.context("a request to GET /")
.topic.is.a.request("GET /")
.vow.it.should.have.status(200)
.vow.it.should.have
.header("content-type", "text/html; charset=utf-8")
.context("contains a body that")
.topic.is.property('body')
.vow.it.should.be.ok
.vow.it.should.include.string("hello world")
.suite().run({
reporter: is.reporter
}, function() {
console.log("finished");
is.end();
})
这使用 vows-is .
这篇关于Node.js测试RESTful API(vows.js?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!