2015年3月21日星期六

Week10: Assertion and Unit Tests

This week we explored assertions, unit tests, and tracing function calls.
When you do

assert a_condition
you're telling the program to test that condition and trigger an error if the condition is false.
Syntax: assert  « condition » ,  « error_string »
Meaning: If the condition fails,
        raise AssertionError( « error_string »)
I don't really understand why we should use assertions. Although the handout said that assertions can help us avoid 'nosiy' output and save the time of testing, I didn't really see any examples to prove the efficiency of using assertions.Since the strike is on, I have no one to ask.

I found a website that provides some examples:
https://wiki.python.org/moin/UsingAssertionsEffectively



没有评论:

发表评论