testing the unpredictable

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

testing the unpredictable

Non deterministic tests

Fran Iglesias

November 02, 2018

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

15 slides
  1. Testing the unpredictable Elements beyond our system: • Randomness •

    Time • File system You can’t rely on their behavior
  2. 1. Things that are using unpredictable components They are global

    state dependencies Isolate and extract Invert dependency Stub for testing
  3. Example class User { private $id; private $name; public function

    __construct(string $name) { $this->id = Uuid::uuid4(); $this->name = $name; } }
  4. Example class User { private $id; private $name; public function

    __construct( UserId $id, string $name ) { $this->id = $id; $this->name = $name; } }
  5. 2. Things that are unpredictable Don’t test what you don’t

    own Test for properties of the output, not the output itself
  6. Example class PasswordGeneratorTest extends TestCase { public function testShouldBeLongEnough() {

    $password = $this->generator->generate(); $this->assertTrue(strlen($password) > 9); } }
  7. Dependency Inversion High level modules should not depend on low

    level modules, both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions.

More Decks by Fran Iglesias

Other Decks in Programming