I am new to unit testing/TDD and having problem getting my head certain aspects of it. For example I am not sure how complete the tests should be imagine the following scenario.
I am writing a test to ensure I get the correct prices for a product. A product can come in different sizes and bought in a number of defined quantities. The price of the product will reflect the size and quantity.
For example:
Product A has the pricing matrix below (quantity down the side and size along the top)
----------------------------
| | xs | s | m | l |
----------------------------
| 250| 10 | 20 | 50 | 100 |
----------------------------
| 500| 20 | 40 | 60 | 110 |
----------------------------
| 1000| 15 | 25 | 55 | 105 |
----------------------------
| 1500| 12 | 22 | 52 | 102 |
----------------------------
Now say I was writing tests for a class method
Pricer.GetPrice(Product p, string size, int quantity)
Should I test for every product/size/quantity combo? as you can imagine this could mean a large number of tests.
If the prices are sourced from a data store and thus liable to change how do you keep your tests correct or is that just a annoying by product?
Also does anyone have any good links to read regarding writing tests/TDD. Maybe going through CRUD/Repositories as this seems a bit of a chicken and egg type scenario.
It sounds like there are two elements to your pricing logic.
A price matrix data structure mapping (size, quantity cutoff) pairs to prices.
A function that takes a price matrix and a
Productinstance and returns a price.Testing the price matrix is meaningless; the numbers are arbitrary. If you feel you need to test the function, I would pass it different fake, hard-coded test matrices with different mock products and test to verify that the right price comes out. The most relevant edge cases are probably when you ask for a price for a cutoff quantity exactly or off-by-one from one.