我有一个模块使用imageResizer
和另一个模块graphicsmagick
调整图像大小apiCaller
,该模块有两个函数,一个用于get
请求,另一个用于post
请求对于request
请求,请使用imageResizer
模块。
在apiCaller.get
我调用apiCaller.post
时,如果获取请求成功,则调用触发图像大小调整的函数,然后调用exports.imageResizer = function (arguments) {
async.series([
function(callback) {
apiCaller.get(callback);
},
function(callback) {
gm("filepath")
.resize("sizes")
.write("destinationPath", function (err) {
if(err) // do something
}, callback());
},
function(callback) {
apiCallerPost(arguments)
}
]);
}
。{/ p>
有些事情是这样的:
apiCaller = {};
apiCaller.get = function (arguments, callback) {
// setup variables and stuff
function _callback (error, response, body) {
if (error) {// do somethind}
else {callback(null, body}
}
request.get(options, _callback);
}
module.exports = apiCaller;
apiCaller.get
我的问题是哪种测试方法最好?
将apiCaller.post
和request
作为最佳方法? sinon
模块本身怎么样?那还需要存根吗?
我正在使用chai
,mocha
,proxyquire
和public class FakeClass : IGettProxy {
public Task<List<CityDetails>> getCity(){
// here goes your fake implementation, to be injected on your controller.
}
// Remember to implement the other method
}
。