Any thoughts/opinions on whether it’s better for tests to have known values or if they should recalculate things, specifically for integration or end-to-end tests?
For example, let’s say you have an API that calculates sales tax. Using pseudocode for examples, would you prefer:
expectedTaxValue = str(round(amount * sales_tax, 2))
or would you prefer something like:
expectedTaxValue = "6.16" // 72 dollars at 8.55% rounds up to to 6.16
I lean towards calculations, as many of my tests lean more towards property testing, where the inputs are somewhat varaible (i.e maybe I use the same test to test the min, max, and a half-dozen random values in and outside the acceptable range). This ends up with my implementing some logic sometimes that’s in the requirements. Balancing act of writing a flexible test with diverse coverage vs. a test with known values. I think the strongest argument for the fixed values is that if you’re treating the test as documentation, it does a good job of making the requirements obvious (w/o someone having to read/understand the code).
Any one else have any thoughts?
Cross posted on r/softwaretesting