[openlp-dev] Need Better Tests

Raoul Snyman raoul at snyman.info
Wed Jun 8 12:35:09 EDT 2016


Guys, 

Our tests are not good enough. We recently changed the way we do string interpolation, and that had introduced a number of bugs that could have been avoided with proper testing.

File "E:\bzr\openlp\trunk\openlp\plugins\songs\lib\mediaitem.py", line 606, in generate_slide_data
verse_def = '{tag}{label}'.format(tzg=verse_tag, text=verse[0]['label'])
KeyError: 'tag'

This is such a simple bug ("tag" vs "tzg"), and yet the tests don't pick it up. What use are our tests when they don't even pick up a bug like this? 

I've said it before and I'm going to say it again: it's time to step up our testing. What we have is not good enough. 

It's much easier to write years when you're writing a bunch of tests for a particular section of the code. This way you're familiar with the code when you're writing the tests and is easier to get your head around how to write the tests you need. Don't just write one small test that doesn't actually do anything. You're not making good use of your own time, and you're leaving OpenLP in the lurch. 

If you're struggling to test a piece of code, you probably need to refactor the code into smaller functions. Rather than passing global or class-level variables around, use function parameters. This makes your code easier to test. 

Use test coverage. If you're using nose, run it with coverage (instructions are on the wiki), if you're running nose 2, install python3-cov and it should be automatically enabled. Test coverage helps to gamify writing tests - you'd be surprised at how much of a kick you'll get out of writing tests. 

If you're unsure of anything, or need to learn how to use MagicMock and patch, don't hesitate to ask me.

R. 
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openlp.io/pipermail/openlp-dev/attachments/20160608/45deff58/attachment.html>


More information about the openlp-dev mailing list