简体   繁体   中英

how to write Unit Test for lambda in Istanbul?

I have a lambda function which will get triggered on event of kinesis Data stream with an array for record.

 exports.handler = function(event, context, callback) {
     event.Records.forEach(function(record) {
         var payload = new Buffer(record.kinesis.data, 'base64');
         var stringPayload = payload.toString();
         //API call  
     });
 }

I am trying to write test cases for this lambda in Istanbul. I have configured Istanbul, and can see the default coverage - but I don't know how to proceed further.

Does anyone know how this can be done? or can point me to the documentation on how to do this?

My understanding is that we cannot write unit test for lambda function since they are anonymous functions. The way I did this in my projects is

  1. to ensure the calls from the lambda are execute with appropriate parameters.
  2. Also, if it is modifying certain data, then check if the expected modifications are actually made as per the test design.
  3. any other verifiable actions that the lambda is taking.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM