TIL: more about using zero in testing

Three testers walk into a bar…and we all know that they order, one beer, zero beer and minus one beer! We also all know that they need to order zero beers because the behaviour of zero can be different from the behaviour of other numbers.  We all test with zeros for this reason. Recently I have learned something more about the behaviour of zero that is helping me to test..

I am doing Typescript tutorials to help me automate tests and recently learned more about behaviour with zeros which helped me to understand the cause of a bug. I have recently learned about conditional narrowing, which can be used to check the type of a value in TypeScript. If the && operator or the || operator are used for truthiness narrowing then zero is coerced to false. The && and || operators treat zero in the same way as are NaN, “”(the empty string), 0n (the bigint version of zero), null and undefined. This means that truthiness narrowing does not treat zero as a number, it treats zero as false

A friend of mine used this knowledge and found a bug in which the user could enter zero but was not able to save the zero that they had entered. The application could not save zero because its logic said that zero was false so was not a number.

Zero is a curious thing and I am using what I have just learned about to help me test. 

Additional Learning Resources:

Published by Mike Harris

Mike has been a testing professional for over 20 years. He has been a Test Lead and has also worked as a part of waterfall, lean and agile teams. He has set up and led a Testing Community of Practice and been part of a successful agile transition. He is Vice-Chair of the British Computer Society’s Specialist Interest Group in Software Testing. He also contributed to the e-books Testing Stories and How Can I test This?

Leave a comment

Design a site like this with WordPress.com
Get started