zoukankan      html  css  js  c++  java
  • python3 unittest

     
    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 %
     
     
     
     
     
     
     
     
     
     
     
     
     
     

  • 相关阅读:
    一个人的旅行 dij(),评测的时候有点惨
    CodeFroce Round 340 div2 E XOR and Favorite Number【莫队算法】
    [HihoCoder-1185] 连通性·三 【tarjan+缩点】
    2017百度之星初赛(A)1001,1005,1006解题报告
    HDU 5961&AOJ 821 传递
    pair
    优先队列 priority_queue
    ccf 201903-5
    memset 和 fill 的区别
    ccf 20190302
  • 原文地址:https://www.cnblogs.com/sea-stream/p/14181691.html
Copyright © 2011-2022 走看看