1 sensing & separation feathers ch 3 steve chenoweth, rhit
DESCRIPTION
3 E.g., public class NetworkBridge { public NetworkBridge(EndPoint [] endpoints) { … } public void formRouting(String sourceID, String destID) { … } … } How do we write tests for this? What if the hardware is not available? This is the “sensing and separation” problem.TRANSCRIPT
![Page 1: 1 Sensing & Separation Feathers Ch 3 Steve Chenoweth, RHIT](https://reader038.vdocuments.us/reader038/viewer/2022101123/5a4d1beb7f8b9ab0599e4542/html5/thumbnails/1.jpg)
1
Sensing & Separation
Feathers Ch 3Steve Chenoweth, RHIT
![Page 2: 1 Sensing & Separation Feathers Ch 3 Steve Chenoweth, RHIT](https://reader038.vdocuments.us/reader038/viewer/2022101123/5a4d1beb7f8b9ab0599e4542/html5/thumbnails/2.jpg)
2
How to break dependencies
1. Sensing – Break dependencies in order to sense, whenever we can’t access values our code computes.
2. Separation – Break dependencies to separate when we can’t even get a piece of code into a test harness to run.
Right – You can’t test the sled unless the dogs are in the harness!
Q10
![Page 3: 1 Sensing & Separation Feathers Ch 3 Steve Chenoweth, RHIT](https://reader038.vdocuments.us/reader038/viewer/2022101123/5a4d1beb7f8b9ab0599e4542/html5/thumbnails/3.jpg)
3
E.g.,
public class NetworkBridge{
public NetworkBridge(EndPoint [] endpoints) {…}public void formRouting(String sourceID, String destID) {…}
…}
How do we write tests for this?What if the hardware is not available?This is the “sensing and separation” problem.
![Page 4: 1 Sensing & Separation Feathers Ch 3 Steve Chenoweth, RHIT](https://reader038.vdocuments.us/reader038/viewer/2022101123/5a4d1beb7f8b9ab0599e4542/html5/thumbnails/4.jpg)
4
So, we Fake collaborators
• Like the “Mock Objects” you studied in 376:• A mock object is a fake object in the system
that decides whether the unit test has passed or failed.
• In general, a “Fake Object” impersonates some collaborator of your class, when your class is being tested.
![Page 5: 1 Sensing & Separation Feathers Ch 3 Steve Chenoweth, RHIT](https://reader038.vdocuments.us/reader038/viewer/2022101123/5a4d1beb7f8b9ab0599e4542/html5/thumbnails/5.jpg)
5
Fake Tests are Real Tests
• May not show everything, but• We try to get close!• We hope for small, well-understood pieces.
Right – Is the chocolate working for you?How about the berries?
Q11
![Page 6: 1 Sensing & Separation Feathers Ch 3 Steve Chenoweth, RHIT](https://reader038.vdocuments.us/reader038/viewer/2022101123/5a4d1beb7f8b9ab0599e4542/html5/thumbnails/6.jpg)
6
Exampleimport junit.framework.*;public class SaleTest extends TestCase{
public void testDisplayItem() {FakeDisplay display = new FakeDisplay();Sale sale = new Sale(display);
sale.scan(“1”);assertEquals(“Milk $3.99”, display.getLastLine3());
}}