Appendix B. Source Code
Test Doubles
import org.hamcrest.Description;import org.hamcrest.TypeSafeMatcher;public class PremiumPurchaseMatcher extends TypeSafeMatcher<Purchase> { @Override public boolean matchesSafely(Purchase purchase) { return purchase.getPrice() > 1000 && purchase.getItemCount() < 5; } @Override public void describeTo(Description desc) { desc.appendText("A purchase with the " + "total price > 1000 and fewer than 5 items"); }}
Data-driven and Combinatorial Testing
Get Developer Testing: Building Quality into Software now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.