Unit Testing in Serverless - tutorial including DynamoDB

Поделиться
HTML-код
  • Опубликовано: 28 фев 2020
  • In this video we'll learn about unit testing in Serverless and how we can also unit test interactions with AWS services such as DynamoDB
    Code for starting this video:
    github.com/SamWSoftware/Serve...
    Code for completed Lesson
    github.com/SamWSoftware/Serve...
  • НаукаНаука

Комментарии • 33

  • @PeteWhelan
    @PeteWhelan 4 года назад

    Great video, thanks again Sam! Enjoyed this tutorial.

  • @shwenansuwai2481
    @shwenansuwai2481 4 года назад

    Love your channel. Thank you for the lessons.

  • @flaviomovil
    @flaviomovil 2 года назад

    Thanks for this video Sam!! Was great! :) help me a lot!

  • @JeanYvesP
    @JeanYvesP 4 года назад

    That is another great video!

    • @CompleteCoding
      @CompleteCoding  4 года назад

      Thanks! The next one on integration testing serverless Lambdas will be coming out shortly

  • @neosarchizo
    @neosarchizo 4 года назад

    Thanks for good video again!

  • @davidwalters76
    @davidwalters76 3 года назад

    basically all your vids 👍

  • @0301311
    @0301311 3 года назад +4

    Testing for S3 is missing !

    • @CompleteCoding
      @CompleteCoding  3 года назад

      With S3 there isn't a library that I've found that works as well as this one does for dynamo. Since these are meant to be unit testing I would mock the s3 service to create the tests.

  • @PeteWhelan
    @PeteWhelan 4 года назад +2

    Note to anyone using this tutorial having problems running Jest:
    Install Jest Globally AS WELL AS npm install --save-dev jest.

    • @CompleteCoding
      @CompleteCoding  4 года назад +1

      Nice spot Pete

    • @cristianecheverria3995
      @cristianecheverria3995 4 года назад +2

      Or instead of adding JEST Globally, you can add a script to package.json like "test": "jest"
      And then just run "npm run test"

  • @2ederson
    @2ederson 3 года назад

    Hi! Quick question, using this same code or a similar one, If I wanted to use jest testing WITHOUT mocking the Database, using the real DynamoDB, does the configuration change or any additional changes to perform? I'm currently trying to make a change in the project, from having the DynamoDB configuration in Handler to a proper Dynamo.js file, but I seem to get the error: UnrecognizedClientException: The security token included in the request is invalid.
    I'm not sure if this stems from handler reading the dynamo configuration from serverless.yml, and the Dynamo.js file does not read it
    Any answer is appreciated.

    • @CompleteCoding
      @CompleteCoding  3 года назад

      You would have to change the configuration in Dynamo.js so that it uses the correct AWS credentials to access the real database when running a test. Add something like this to the top of the Dynamo.js file in the (isTest) block. This uses the credentials for the profile when running the lambda.
      var credentials = new AWS.SharedIniFileCredentials({profile: 'work-account'});
      AWS.config.credentials = credentials;

  • @JorgeNunez22
    @JorgeNunez22 3 года назад +2

    Why Skipped the S3 unit tests???

    • @CompleteCoding
      @CompleteCoding  3 года назад

      With S3 there isn't a library that I've found that works as well as this one does for dynamo. Since these are meant to be unit testing I would mock the s3 service to create the tests.

  • @karthikr7038
    @karthikr7038 3 года назад +1

    I am getting error while executing jest with @shelf/jest-dynamodb added in jest.config.js file.

    • @CompleteCoding
      @CompleteCoding  3 года назад +1

      Try following the previous video on serverless offline first. There may be some steps in that that are needed to get jest to work.

    • @karthikr7038
      @karthikr7038 3 года назад

      @@CompleteCoding java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException

    • @rendelllasola66
      @rendelllasola66 3 года назад +1

      You can use jest-dynalite which is a fork of jest-dynamodb as replacement because it doesn't require Java.

    • @CompleteCoding
      @CompleteCoding  3 года назад

      @@rendelllasola66 Thanks for point that out

  • @shahidabbas2932
    @shahidabbas2932 2 года назад

    Hi, Sir i want to contact you .

    • @CompleteCoding
      @CompleteCoding  2 года назад

      My details are in the 'about' section of the channel page

  • @dhanwadc
    @dhanwadc 4 года назад

    First view

  • @karthikr7038
    @karthikr7038 3 года назад

    java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException

    • @CompleteCoding
      @CompleteCoding  3 года назад

      This sounds like you haven't got the Java processor required. If you follow this video on setting up serverless-offline it will show you how to install this. Then it should all work.
      ruclips.net/video/ul_85jfM0oo/видео.html

  • @adityanair3566
    @adityanair3566 Год назад +1

    Dynamo intialisation file is written in TS. To compile ts file in jest, I read you need to include 'ts-jest' as preset. But to use dynamo
    local, we need to use "@shelf/jest-dynamodb" as preset. How can I add two presets in one jest config file? Please help me out.
    Great video btw!