擅长:python、mysql、java
<pre><code>from contacts.models import Contact # import model Contact
...
class ContactTests(TestCase): # start a test case
"""Contact model tests."""
def test_str(self): # start one test
contact = Contact(first_name='John', last_name='Smith') # create a Contact object with 2 params like that
self.assertEquals( # check if str(contact) == 'John Smith'
str(contact),
'John Smith',
)
</code></pre>
<p>基本上,它会检查str(contact)=‘John Smith’,如果不是,那么assert equal失败,测试失败,它会通知您该行的错误。</p>
<p>换句话说,assertEquals是一个函数,用于检查两个变量是否相等,以便进行自动测试:</p>
<pre><code>def assertEquals(var1, var2):
if var1 == var2:
return True
else:
return False
</code></pre>
<p>希望有帮助。</p>