The assertion content is an important part of the automation script, and the assertion is set correctly to help us determine the result of the test case execution.
Assertion method
- assertequal (A, B) determine a==b
-
- asserttrue (x) bool (x) is True
- assertfalse (x) bool (x) is False
- assertis (A, B) A is b
- assertisnot (A, B) A is not B
- assertisnone (x) x is none
- assertisnotnone (x) x was not "none"
Li> assertin (A, b) A in B
- assertnotin (A, b) A not in B
- assertisinstance (A, B) Isinstance (A, b)
- assertnotisinstance (A, B) not isinstance (A, b)
Instance
1 #Coding=utf-82 ImportUnitTest3 fromCaculatorImportMath4 classTestmath (unittest. TestCase):5 defsetUp (self):6 Print("Start Test")7 8 defTest_add (self):9J=math (5,10)TenSelf.assertequal (J.add (), 15) One #use case failure Scenario A #self.assertequal (J.add (), - deftest_add1 (self): -J=math (5,10) theSelf.assertnotequal (J.add (), 10) - - deftest_add2 (self): -J=math (5,10) +Self.asserttrue (J.add () >10) - + deftest_add3 (self): ASelf.assertis ("Blog",'Blog') at #self.assertis ("blog", ' abc ') - - deftest_add4 (self): -Self.assertin ("Blog","Hello, blog") -Self.assertin ("888","Hello, blog") - in defTearDown (self): - Print("Test End") to + if __name__=='__main__': - #Constructing test Sets theSuite=UnitTest. TestSuite () *Suite.addtest (Testmath ("TEST_ADD2")) $ #Perform testsPanax NotoginsengRunner=UnitTest. Texttestrunner () -Runner.run (Suite)
Python Unit Test Framework-unittest (ii) assertions