clean and quality unit tests

Post on 10-May-2015

116 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

Talk about readability and high quality of unit tests written in PHPUnit

TRANSCRIPT

Clean & Quality unit tests

Wojtek Zieliński

@codecleaner

•  Names matters

•  Exceptions

•  Test Doubles

•  Stubbing Collections

•  Arrange Act Assert

What’s it all about?

Names matters

Test a single concept in each test function

Robert C. Martin

Exceptions

Test Doubles

How does getMock() really work?

•  Does Configuration class exist?

•  Create Mock_Configuration_123abc class extends Configuration class

•  Create instance of that class

•  Return instance

How does getMock() really work?

•  Does Configuration class exist?

•  Create Mock_Configuration_123abc class extends Configuration class

•  Create instance of that class

•  Return instance

•  Create Configuration class

Stubs provide canned answers to calls made during the test

"Mocks Aren’t Stubs" Martin Fowler

Mocks are objects pre-programmed with expectations which form a specification of the calls they are expected to receive

"Mocks Aren’t Stubs" Martin Fowler

Stubbing collections

Arrange Act

Assert

It’s all about readability

What’s next?

Questions?

Wojtek Zieliński

@codecleaner

top related