Published on

Not Using the Same Values As Test Data When Testing Objects with the Same Type

Authors

Today I needed to debug the cause of a serious issue. Essentially the symptom of the bug was that two fields in an object had the same data type but were assigned to each other i.e. I was expecting field A=B and C=D but instead as A and C were the same data type they were A=D and C=B. After doing a bit of digging I found the bug.

My question at that point was how was this not picked up in a test? After looking at a test I saw that the test data for both these values had the exact same default value hence when running a unit test this bug was not breaking the unit test. I promptly gave the test data for these variables more realistic values and different values to each other and the test broke. I fixed the issue making the tests pass and resolved this bug.

Long story short when testing try to not use the same values as test data for fields that have the same type and as mentioned in a previous post use data that is as close to what the system will be fed in a real environment to root out bugs like this.