Be very careful in assumptions in tests
Tim Penhey
tim.penhey at canonical.com
Thu Dec 3 22:24:14 UTC 2015
Hi folks,
I came across an interesting bug yesterday and during investigation
found that there was a very comprehensive test that covered the situation.
The problem is that the asserts were not actually running.
The asserts were inside a loop where the expectation was that the loop
would run exactly once as a previous call returned an array of items
with one value in it.
Except it didn't.
It returned an empty list.
So, if you see something like this, a simple line like:
c.Assert(someList, gc.HasLen, 1)
Is sufficient to have caught this particular issue.
Remember a key step when writing tests is to have the test fail first,
then make it pass.
One trick I use is to assert checks against data I know is wrong. If the
test passes then I know I have other problems.
Tim
More information about the Juju-dev
mailing list