Date post: | 12-Feb-2017 |
Category: |
Software |
Upload: | brian-fenton |
View: | 669 times |
Download: | 0 times |
https://twitter.com/sarahmei/status/633895726993440768
Coverage tricks
• if (false) this_function_call_is_covered();
• // @codeCoverageIgnore
• multiple checks on the same line
Example
for ($i = 0; $i > 10; $i++) { if ($i % 2 === 0) { echo "Even: "; } else { echo "Odd: "; } echo $i, "\n"; }
Randomness
• Can the randomness come from outside?
• Do you need to know the exact value?
• Can you just verify “randomness”?
Namespace tricknamespace My\Namespace { function random() { return 7; } }
namespace My\Tests; … function testRandomNumberGenerator() { $this-‐>assertSame(7, random()); }
Good unit tests
• Single reason to fail
• Clearly named
• testGuestCanRegisterWithValidInformation
• testProcessData
Test smells
• Too many mocks
• Lots of setup required
• Can’t test w/o database/network/etc…
• Can’t inject mocks where needed
Test smells
• Mocks returning mocks
• Flaky results
• Unrelated code changes breaking tests
• Testing the implementation