Skip to content
This repository was archived by the owner on Nov 26, 2021. It is now read-only.
Pyroka edited this page May 5, 2014 · 4 revisions

HMS includes a number of tests to help you check that the code you are writing is not introducing errors into the system. To run the test your will need to install PHPUnit and Behat, the easiest way to do this is through Composer.

Check your installation

Navigate to http://localhost/hms/test.php, you should see a list of test-suites.

Running the PHPUnit Tests

Each item in the list represents a suite of tests, (as-in, each item represents one file in the app/Test/Case folder) clicking on any one of them will run all the tests that file specifies and report the results, on that results screen it should also give you the option to run the tests again whilst checking for code coverage.

The special case test is the 'AllTests' one, which runs everything (and will take a while) it's a good idea to run this before you commit to make sure you've not broken anything else with your changes.

Running the Acceptance Tests

The acceptance tests use the Behat framework, and can be run by running the following command in your hms directory bin\behat. It is important to back-up your app\Config directory before running the tests, as the tests will alter files in this dir (the tests will attempt to return the Config files back to their initial state but encountering certain errors will prevent this).

Making New Tests

There's a pretty good run-down of how to make new tests in the [http://book.cakephp.org/2.0/en/development/testing.html](CakePHP docs), follow that guide and try to make sure that your tests are named sensibly, and that they pass reliably (flaky tests are the worst), if you have any questions e-mail pyroka@gmail.com and I'll give you a hand, I'll also update this guide with any questions I get to help future devs.

Testing Guidelines

Generally I like the mantra of 'Test smart, not hard', by all means check your code coverage but take the results with a grain of salt, unless it's very important code that could be used in lots of things then anything around 70% is fine, write tests around the fragile bits (you should know what they are) or around the bits you think might change in the future (if someone changes that, it'll break everything, so I'll put in a test) and if you want your tests checking over give one of the other devs an e-mail.

Clone this wiki locally