Plugin Test Methods
The full list of test methods and how to use them.
Strike
The complete guide to writing tests for your plugins.
Page
3
of
4.
Introduction
You know how to make plugin test case classes and you know how to do just about everything with them except to actually test stuff. Well, listed below are all of the assertions used in tests. If you're unfamiliar with what an assertion is in code testing, it is basically a requirement of something that must be true in order for that test to pass. It's a necessary condition. If any assertion within a test method fails the entire test method fails and it goes on to the next one.
Assertions
All of these are methods of the plugin test classes themselves and hence are accessed by using self.assertWhatever in your test methods. These are sorted in order of relative usefulness.
assertResponse(query, expectedResponse)- Feedsqueryto the bot as a message and checks to make sure the response isexpectedResponse. The test fails if they do not match (note that prefixed nicks in the response do not need to be included in theexpectedResponse).assertError(query)- Feedsqueryto the bot and expects an error in return. Fails if the bot doesn't return an error.assertNotError(query)- The opposite ofassertError. It doesn't matter what the response toqueryis, as long as it isn't an error. If it is not an error, this test passes, otherwise it fails.assertRegexp(query, regexp, flags=re.I)- Feedsqueryto the bot and expects something matching the regexp (nom//required) inregexpwith the suppliedflags. Fails if the regexp does not match the bot's response.assertNotRegexp(query, regexp, flags=re.I)- The opposite ofassertRegexp. Fails if the bot's output matchesregexpwith the suppliedflags.assertHelp(query)- Expectsqueryto return the help for that command. Fails if the command help is not triggered.assertAction(query, expectedResponse=None)- Feedsqueryto the bot and expects an action in response, specificallyexpectedResponseif it is supplied. Otherwise, the test passes for any action response.assertActionRegexp(query, regexp, flags=re.I)- Basically likeassertRegexpbut carries the extra requirement that the response must be an action or the test will fail.
Utilities
feedMsg(query, to=None, frm=None)- Simply feedsqueryto whoever is specified intoor to the bot itself if no one is specified. Can also optionally specify the hostmask of the sender with thefrmkeyword. Does not actually perform any assertions.getMsg(query)- Feedsqueryto the bot and gets the response.