unittest testing framework assertion set _2_

During execution of the test case, whether performed by use cases, necessary to determine actual results to the test results obtained are equal decision. Here are some common assertions operation:

assertEqual (a, b, msg = None) is equal to a determined b, equal by asserting
assertNotEqual (a, b, msg = None) determines whether a not equal b, equal by asserting
assertTrue (a, msg = None) determines whether a is True, equal by asserting
assertFalse (a, msg = None) determines whether a to False, equal by asserting
assertIn (a, b, msg = None) b determines whether comprising a, equal by asserting
assertNotIn (a, b, msg = None) b determines whether or not containing a, equal by asserting
assertIs (a, b, msg = None) determines whether b is a, equal by asserting
assertIsNot (a, b, msg = None) b determines whether or not a, equal by asserting
assertIsNone (a, msg = None) determines whether a None, equal by asserting
assertIsNotNone (a, b, msg = None) determines whether or not a None, equal by asserting
from cgi_projects.selenum_test.count import Count
from cgi_projects.selenum_test.count import Torf
import unittest


class TestCount(unittest.TestCase):
    def setUp(self):
        print("start")

    def test_add(self):
        j = Count(2, 3)
        # assertEqual(a,b):检查a == b
        self.assertEqual(j.add(), 5, msg="assertEqual: no equal")

    def test_add2(self):
        j = Count(44, 90)
        self.assertNotEqual(j.add(), 135, msg="assertNotEqual:no equal")

    def test_zero(self):
        self.assertTrue(Torf(0).is_zero(), msg="assertTrue: result is true")

    def test_numb(self):
        self.assertFalse(Torf('a').is_numb(), msg="assertFalse: result is False")

    def test_case1(self):
        a = "hello"
        b = "hello word"
        self.assertIn(a, b, msg= "assertIn: a in b ")

    def test_case2(self):
        a = "python"
        b = "java"
        self.assertNotIn(a, b, msg="assertNotIn: a not in b ")

    def test_case3(self):
        a = 1
        b = 1
        self.assertIs(a, b, msg="assertIs: a is b")

    def test_case4(self):
        a = 1
        b = 3
        self.assertIsNot(a, b, msg="assertIsNot: a is not b")

    def test_case5(self):
        a = None
        self.assertIsNone(a, msg="assertIsNone: a is none")

    def test_case6(self):
        a = 'b'
        self.assertIsNotNone (a, MSG = "assertIsNotNone: None Not a IS") 

    # DEF test_case7 (Self): 
    # a = the Count (2,. 3) 
    # b = the Count (. 3,. 4) 
    # # determines whether b, a one example 
    # self.assertIsInstance (a, b, MSG = "assertIsInstance:") 

    # DEF test_case8 (Self): 
    # = a 'SECOND' 
    # = b "SE" 
    # a # determines whether an instance b 
    # self. assertNotIsInstance (A, B, MSG = "assertIsInstance:") 

    DEF the tearDown (Self): 
        Print ( "End") 


IF the __name__ == '__main__': 
    Suite = unittest.TestSuite () 
    suite.addTest(TestCount("test_add"))
    suite.addTest (TestCount ( "test_add2") ) 
    suite.addTest (TestCount ( "test_zero"))
    suite.addTest(TestCount("test_numb"))
    suite.addTest(TestCount("test_case1"))
    suite.addTest(TestCount("test_case2"))
    suite.addTest(TestCount("test_case3"))
    suite.addTest(TestCount("test_case4"))
    suite.addTest(TestCount("test_case5"))
    suite.addTest(TestCount("test_case6"))
   # suite.addTest(TestCount("test_case7"))
    suite.addTest(TestCount("test_case8"))
    runner = unittest.TextTestRunner()
    runner.run()

  

 

Guess you like

Origin www.cnblogs.com/ninijiang/p/10993085.html