我一直在用回环测试项目为我的循环后端编写测试。后端设置了回环组件存储,以便提供apis将文件存储在文件系统中。我希望使用回环组件存储提供的远程api来测试文件上载,使用如下所示:
describe('Containers', function() {
lt.it.shouldBeAllowedWhenCalledByUserWithRole(TEST_USER, someRole,
'POST', '/api/containers/somecontainer/upload', somefile);
});但没有运气..。没有这方面的文件。我不知道它是否有可能被测试。有什么想法吗?
提前感谢
一些链接:
发布于 2016-01-05 13:28:57
您应该考虑使用超测试。它依赖于超剂,允许您在REST上执行http请求,并对响应对象进行断言。
然后,可以使用超级代理法构建可以包含文件的多部分表单数据请求。
使用mocha描述测试的代码如下所示:
var request = require('supertest');
var fs = require('fs');
var app = require('./setup-test-server-for-test.js');
function json(verb, url) {
return request(app)[verb](url)
.set('Content-Type', 'multipart/form-data');
};
describe("User",function() {
it("should be able to add an asset to the new project", function(done){
var req = json('post', '/api/containers/someContainer/upload?access_token=' + accessToken)
.attach("testfile","path/to/your/file.jpg")
.expect(200)
.end(function(err, res){
if (err) return done(err);
done();
});
});
it("should have uploaded the new asset to the project folder", function(done){
fs.access('/path/to/your/file.jpg', fs.F_OK, function(err){
if (err) return done(err);
done();
});
});
};https://stackoverflow.com/questions/34065687
复制相似问题