DEV Community

Discussion on: Can someone experienced in writing tests expand on the mental models of unit tests?

 
cristiano profile image
cristiano • Edited

Thanks Austin, so it seems that when writing tests we should be making sure that values that should be accepted do pass and values which should not, won't.

Also its important to have in consideration that the test will evolve over time as we think of other cases to test, is this correct?

Considering everything together with your additions, provided that all statements are true the test itself should pass:

  • Price that is less than 0 has to be invalid
  • Price that is equal to 0 has to be invalid
  • Price equal or greater than 0.01 has to be valid
  • Price is Infinity or NaN has to be invalid
  • Price is equal to non-numeric value has to invalid

I think this was one aspect that confused me, the goal is not to get the test to pass with all the values that would typically be accepted and needed for the app to work but we also should try our code with the values that shouldn't pass and would make the app break. Then we can make adjustments to our code to make sure a feature works as it should, not the test.

If this is correct than this is really helpful! 🙏

Thread Thread
 
pentacular profile image
pentacular

For correctness you want to test the transitions between valid and invalid, yes.

There are generally an infinite number of valid and invalid values, but usually a finite number of discontinuities in the domain of a function.