Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you test code written against AWS API [closed]

I'm writing an application in Java that will upload a file up to AWS S3. The file will be given to the application in an argument, not hardcoded. I'd like to write tests to ensure that the file actually gets uploaded to S3. The test will be written before the code for TDD. (I have actually already written the code, but I'd like to ingrain TDD practices into all of my work as a habit)

How exactly would I go about doing this? I will be using JUnit as that's what I'm most familiar with.

Thanks in advance for any help.

like image 534
BrianJakovich Avatar asked Jun 06 '11 01:06

BrianJakovich


People also ask

What is AWS SDK mock?

The mocking library for AWS SDK for JavaScript (v3) can be used in any JavaScript unit testing framework. Internally, it uses Sinon. JS to create robust stubs in place of the SDK calls. You can install it with your favorite package manager.

Which of these are used to test the lambda function?

This is how a typical Lambda function is written and tested using the AWS Toolkit for Eclipse. For more advanced use cases, you can use the S3 Event and DynamoDB Event examples provisioned by AWS Lambda.


1 Answers

The actual uploading and the tests that are doing it are part of your integration testing, not the unit testing. If you wrap the S3 API in a very thin class, you will mock that class for unit testing of your business classes, and you will use the real implementation for integration testing.
If you have decided, your business classes to take directly the AmazonS3 interface, then for unit testing you have to mock that one.

The actual exploratory testing (learning and verifying) if and how amazon s3 works is what you actually do in separate experimental setup.

P.S. I do not recommend using the AmazonS3 interface directly in your business classes, rather, wrap it in a thin interface of yours, so that if you decide to change the 'back-end storage' you can easily change it.

like image 79
Op De Cirkel Avatar answered Oct 19 '22 09:10

Op De Cirkel