python3 unittest

python

 

Code

import unittest

class SimplisticTest(unittest.TestCase):

def test(self):

a = 'a'

b = 'a'

self.assertEqual(a, b)

Output

macname@MacdeMacBook-Pro cherry % python3 -m unittest test.py           

.

----------------------------------------------------------------------

Ran 1 test in 0.000s

OK

macname@MacdeMacBook-Pro cherry %

 

 


 

 

Code

import unittest

class OutcomesTest(unittest.TestCase):

def testPass(self):

return

def testFail(self):

self.assertFalse(True)

def testError(self):

raise RuntimeError('Test error!')

Output

macname@MacdeMacBook-Pro cherry % python3 -m unittest test.py           

.

----------------------------------------------------------------------

Ran 1 test in 0.000s

OK

macname@MacdeMacBook-Pro cherry % python3 -m unittest test.py

EF.

======================================================================

ERROR: testError (test.OutcomesTest)

----------------------------------------------------------------------

Traceback (most recent call last):

File "/Users/macname/Desktop/cherry/test.py", line 8, in testError

raise RuntimeError('Test error!')

RuntimeError: Test error!

======================================================================

FAIL: testFail (test.OutcomesTest)

----------------------------------------------------------------------

Traceback (most recent call last):

File "/Users/macname/Desktop/cherry/test.py", line 6, in testFail

self.assertFalse(True)

AssertionError: True is not false

----------------------------------------------------------------------

Ran 3 tests in 0.001s

FAILED (failures=1, errors=1)

macname@MacdeMacBook-Pro cherry %

 

 

 

 

 

 

 

 

 

 

 

 

 

 

以上是 python3 unittest 的全部内容, 来源链接: utcz.com/z/386879.html

回到顶部