Created
December 20, 2018 23:43
-
-
Save goldbergyoni/a07f88922d5f5063f4be31877334e422 to your computer and use it in GitHub Desktop.
Testing whitebox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ProductService{ | |
| //this method is only used internally | |
| //Change this name will make the tests fail | |
| calculateVAT(priceWithoutVAT){ | |
| return {finalPrice: priceWithoutVAT * 1.2}; | |
| //Change the result format or key name above will make the tests fail | |
| } | |
| //public method | |
| getPrice(productId){ | |
| const desiredProduct= DB.getProduct(productId); | |
| finalPrice = this.calculateVATAdd(desiredProduct.price).finalPrice; | |
| } | |
| } | |
| it("White-box test: When the internal methods get 0 vat, it return 0 response", async () => { | |
| //There's no requirement to allow users to calculate the VAT, only show the final price. Nevertheless we falsely insist here to test the class internals | |
| expect(new ProductService().calculateVATAdd(0).finalPrice).to.equal(0); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment