Selenium 2 31 combat automated testing (skip expected and anticipated failure)

Skip anticipated and expected failure

 

When you run the test, and sometimes need to skip some of the test cases, or skip the test when patients met with a condition, or directly to the test cases to fail. unittest provides an implementation of these requirements decorator.

 

--unittest.skip (reason) 
unconditionally skipping decorative test reasons skipped. --unittest.skipIf (condition, reason)
 if the condition is true, the test is skipped decoration. --unittest.skipUnless (condition, reason)
 Unless the condition is true, skip the decorated test. --unittest.expectedFailure ()
 test is marked as failed. Regardless of whether the results of the failure, unity is marked as failed









 

#coding:. 8 UTF- 
Import the unittest 

class the MyTest (of unittest.TestCase): 

    DEF the setUp (Self): 
        Pass 

    DEF the tearDown (Self): 
        Pass 

    @ unittest.skip ( "skip test") 
    DEF test_skip (Self): 
        Print ( "test AAA") 

    @ unittest.skipIf (. 3> 2, "when the condition is true, the test is skipped") 
    DEF test_skip_if (Self): 
        Print "test BBB" 

    @ unittest.skipUnless (. 3> 2, "when the condition is true, perform a test ") 
    DEF test_skip_unless (Self): 
        Print" the test ccc " 

    @ unittest.expectedFailure 
    DEF test_excepted_failure (Self): 
        self.assertEqual (2, 3) 


IF __name__ __ ==" __ main__ ": 
    unittest.main()

Execution results as shown below:

 

 

 

 

In this example, four test cases created, the first () with decorative illustrated by @ unittest.skip, skip is not performed.
Article () with decorative illustrated by @ unittest.skipIf, is not performed when the condition is true.
Article () with decorative illustrated by @ unittest.skipUnless, when the condition is true executed.
Article by @ unittest.expectedFailure decorative use cases, regardless of whether the result of failure to perform, collectively labeled as a failure, but does not throw an error message.

 

These can also act directly on the test class

#coding:utf-8
import unittest
 ……………
@ unittest.skip ( "skip the test class") 
class MyTest (unittest.TestCase):
...............

  

 

Guess you like

Origin www.cnblogs.com/Rita-LJ/p/11778137.html