Test doubles: Difference between revisions

Created page with " A '''wp:Test double''' is any object that stands in for a real dependency in automated testing. Usually in PHPUnit, we make test doubles for other classes, but you can also double PHP native functions or closures. There are 5 types of Test doubles <ul> <li> Dummy - "A dummy argument" - used as a placeholder when an argument needs to be passed in. <li> Stub - Provides fake or 'canned' data to the System Under Test (<abbr title="System Under Test is the class tha..."
 
No edit summary
Line 3: Line 3:


There are 5 types of Test doubles
There are 5 types of Test doubles
<ul>
 
<li> Dummy - "A dummy argument" - used as a placeholder when an argument needs to be passed in.
; Dummy
<li> Stub - Provides fake or 'canned' data to the System Under Test (<abbr title="System Under Test is the class that the Automated Test is targeting">SUT</abbr>).  
: "A dummy argument" - used as a placeholder when an argument needs to be passed in.
<li> Spy - Records information about how it is used, and can provide that information back to the test.
; Stub
<li> Mock - Defines an expectation on how it will be used, and with what parameters. Will cause a test to fail automatically if the expectation isn’t met.
: Provides fake or 'canned' data to the System Under Test (<abbr title="System Under Test is the class that the Automated Test is targeting">SUT</abbr>).  
<li> Fake - "Looks real, but it's not." An actual (simplified) implementation of the contract, unsuitable for production.  
; Spy  
</ul>
: Records information about how it is used, and can provide that information back to the test.
; Mock
: Defines an expectation on how it will be used, and with what parameters. Will cause a test to fail automatically if the expectation isn’t met.
; Fake
: "Looks real, but it's not." An actual (simplified) implementation of the contract, unsuitable for production.