Search code examples
javatestingjunittddamazon-web-services

How do you test code written against AWS API


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.


Solution

  • 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.