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 %

 

 
 
 
 
 
 
 
 
 
 
 
 
 
 

相关文章:

  • 2021-06-17
  • 2021-08-01
  • 2021-05-29
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
猜你喜欢
  • 2021-07-08
  • 2022-12-23
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
相关资源
相似解决方案