Automated Smoke Testing using PHP Unit
- The Application is installed correctly
- The proper Application Configuration is installed
- The Apache Config is working
- Restler (or other API Framework) is configured correctly
- The Database connection is working properly
# yum install php-phpunit-PHPUnit
If you put all your smoke-tests in an individual XML-file, running the smoke test is a easy as
# phpunit -c smoketest.xml
If you just have one configuration file, with all sort of tests, in different sections, you just point out that you just want to execute your "smoketest" test suite.
# phpunit -c all_tests.xml --group smoketest
PHP Unit is also very useful for writing unit tests for PHP applications. Often, you neeed to prepare or clean-up before and after tests are run. Check out the manual, regarding Fixtures.
Automated testing is also a key concept in Continuous Integration, so I recommend that you get familiar with it!
# yum install curl
To test a GET API method, and send the result to screen, you can use
# curl -v -u 'johan:mypassword' -O /dev/stdout 'http://172.30.4.242/api/v3/getfunc?myparam=myvalue'
Explanation of flags used:
- -v - Use verbose mode, show HTTP Headers. This can be useful when debugging APIs.
- -u 'johan:mypassword' - Provide this HTTP Basic username and password to the server.
- -O /dev/stdout - Send the output to screen.
# curl -v -X POST --data="param1=value1¶m2=value2" -O /dev/stdout 'http://172.30.4.242/api/v3/postfunc'
Use can also use -X to change HTTP method to PUT and DELETE.