Reputation: 3101
I've been looking around for aws-sam-local unit testing strategies and haven't found much. Just looking for suggestions?
Upvotes: 5
Views: 3946
Reputation: 460
To run the 'test_handler.py' in the 'tests' directory you can do the following. You probably don't need all the steps. Do this in the directory where you would do the 'sam build' command.
$ python3 -m venv venv
$ source venv/bin/activate
(venv) $ pip3 install pytest
(venv) $ pip3 install pytest-mock
(venv) $ python3 -m pytest tests/ -v
Upvotes: 4
Reputation: 1426
I generally just recommend unit testing your code how you always would in any project regardless of language. Ex: JUnit for java,
Unique to sam for testing sometimes I maintain several payloads test-case-1.json, test-case-2.json
and you can run
sam local invoke -e test-case-1.json
and validate you got proper outputs either manually or programmatically for more e2e functional testing of your function.
Or if its an API Ill start up the container during build and run some integration tests. Id also recommend running integration tests after actually deploying in to your account in a staging env/alias since that will be most realistic.
Upvotes: 0