Skip to content

Commit

Permalink
update tests readme
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrice committed Sep 7, 2014
1 parent 6f532a9 commit ba47272
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

$ phpunit --version

2) Install WordPress and the WP Unit Test lib using the `install-wp-tests.sh` script. Change to the plugin root directory and type:
2) Install WordPress and the WP Unit Test lib using the `install.sh` script. Change to the plugin root directory and type:

$ tests/install-wp-tests.sh <db-name> <db-user> <db-password> [db-host]
$ tests/bin/install.sh <db-name> <db-user> <db-password> [db-host]

Sample usage:

$ tests/install-wp-tests.sh woocommerce_tests root root
$ tests/bin/install.sh woocommerce_tests root root

**Important**: The `<db-name>` database will be created if it doesn't exist and all data will be removed during testing.

Expand All @@ -34,8 +34,20 @@ A text code coverage summary can be displayed using the `--coverage-text` option

## Writing Tests

TODO
* Each test file should roughly correspond to an associated source file, e.g. the `formatting-functions.php` test file covers code in the `wc-formatting-functions.php` file
* Each test method should cover a single method or function with one or more assertions
* A single method or function can have multiple associated test methods if it's a large or complex method
* Use the test coverage HTML report (under `tmp/coverage/index.html`) to examine which lines your tests are covering and aim for 100% coverage
* For code that cannot be tested (e.g. they require a certain PHP version), you can exclude them from coverage using a comment: `// @codeCoverageIgnoreStart` and `// @codeCoverageIgnoreEnd`. For example, see [`wc_round_tax_total()`](https://github.com/woothemes/woocommerce/blob/master/includes/wc-formatting-functions.php#L155-155)
* In addition to covering each line of a method/function, make sure to test common input and edge cases.
* Prefer `assertsEquals()` where possible as it tests both type & equality
* Remember that only methods prefixed with `test` will be run so use helper methods liberally to keep test methods small and reduce code duplication. If there is a common helper method used in multiple test files, consider adding it to the `WC_Unit_Test_Case` class so it can be shared by all test cases
* Filters persist between test cases so be sure to remove them in your test method or in the `tearDown()` method.

## Automated Tests

Tests are automatically run with Travis-CI for each commit and pull request.
Tests are automatically run with [Travis-CI](https://travis-ci.org) for each commit and pull request.

## Code Coverage

Code coverage is available on [Coveralls](https://coveralls.io/) which receives updated data after each Travis build.

0 comments on commit ba47272

Please sign in to comment.