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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With