This page is archived
We're keeping this page up as a courtesy to folks who may need to refer to old instructions. We don't plan to update this page.
Alternate resources
Assertions are like the answer sheet a teacher uses when grading a multiple choice test. When we write tests our primary objective is to check, or assert, that the state of some system, or the value of some variable, in the specified context matches our expectations. Like saying, "I expect that when I break this cookie in half I'll see chocolate pieces.". If you break the cookie and they are not there you might then decide that this particular cookie does not pass the chocolate chip cookie test. And flag it for review.
There are a lot of different types of assertions that we can make when using SimpleTest and this lesson attempts to demystify what each of the different types of assertions does. There is some really good documentation about the various types of assertions and some examples of using them in the Assertions documentation page on Drupal.org.
Not all of the assertions in SimpleTest are listed there though. For that, your best bet is to look at the API documentation for DrupalWebTestCase, and use the filter field at the top of the table to limit the list to only methods that start with the keyword "assert". This will give you a complete, and up-to-date list of all the assertions.
Basic assertion types reference:
Checking the value of something
- assertTrue
- assertFalse
- assertNull
- assertNotNull
- assertEqual
- assertNotEqual
- assertIdentical
- assertNotIdentical
Checking for the presence of something
- assertPattern
- assertNoPattern
- assertRaw
- assertNoRaw
- assertText
- assertNoText
- assertTitle
- assertNoTitle
- assertUniqueText
- assertNoUniqueText
- assertLink
- assertNoLink
- assertResponse
Checking form elements
- assertFieldById
- assertNoFieldById
- assertFieldByName
- assertNoFieldByName
- assertFieldChecked
- assertNoFieldChecked
- assertOptionSelected
- assertNoOptionSelected
Additional resources
Over the years we've developed some techniques for practicing that we wanted to share. At Drupalize.Me we take hugging seriously. In this tutorial we'll look at the art, and science, of giving a good hug. The Merriam Webster dictionary defines the word hug as; squeeze (someone) tightly in one's arms, typically to express affection.
Did you know there are all kinds of different hugs that you can give? In this tutorial we'll look at:
- Defining what a hug is
- Some of the many types of hugs in the world today
- Precautions you may want to familiarize yourself with before hugging
- And the importance of proper technique
Lets go ahead and get started shall we?