| 1 | ======== |
|---|
| 2 | Testing |
|---|
| 3 | ======== |
|---|
| 4 | |
|---|
| 5 | We use twisted.trial for our tests, to run the test framework run: |
|---|
| 6 | |
|---|
| 7 | trial pkgcore |
|---|
| 8 | |
|---|
| 9 | Your own tests must be stored in pkgcore.test - furthermore, tests must |
|---|
| 10 | pass when ran repeatedly (-u option). You will want at least twisted-2.2 |
|---|
| 11 | for that, <2.2 has a few false positives. |
|---|
| 12 | |
|---|
| 13 | Testing for negative assertions |
|---|
| 14 | =============================== |
|---|
| 15 | |
|---|
| 16 | When coding it's easy to write test cases asserting that you get result xyz |
|---|
| 17 | from foo, usually asserting the correct flow. This is ok if nothing goes |
|---|
| 18 | wrong, but that doesn't normally happen. :) |
|---|
| 19 | |
|---|
| 20 | Negative assertions (there probably is a better term for it) means asserting |
|---|
| 21 | failure conditions and ensuring that the code handles zyx properly when it |
|---|
| 22 | gets thrown at it. Most test cases seem to miss this, resulting in bugs |
|---|
| 23 | being able to hide away for when things go wrong. |
|---|
| 24 | |
|---|
| 25 | Using --coverage |
|---|
| 26 | ================ |
|---|
| 27 | |
|---|
| 28 | When writing tests for your code (or for existing code without any tests), it |
|---|
| 29 | is very useful to use --coverage. Run `trial --coverage <path/to/test>`, and |
|---|
| 30 | then check <cwd>/_trial_temp/coverage/<test/module/name>. Any lines prefixed |
|---|
| 31 | with '>>>>>' have not been covered by your tests. This should be rectified |
|---|
| 32 | before your code is merged to mainline (though this is not always possible). |
|---|
| 33 | Those lines prefixed with a number show the number of times that line of code |
|---|
| 34 | is evaluated. |
|---|