qq_21854029
qq_21854029
2017-11-23 03:00

求大神解决python,unittest测试结果为Ran 0 tests in 0.000s

  • python
  • 测试
  • 单元测试

testadd_run.py
#coding=utf-8
import unittest
from match_ import Match

class Test_match(unittest.TestCase):

def setUp(self):
    print("start test")
def test_add(self):
    t = Match(3,4)
    add=t.add()
    self.assertEqual(add,7,msg="运行成功")
    print("case1")

def test_add2(self):
    t = Match(5,4)
    add = t.add()
    self.assertEqual(add, 9, msg="运行失败")
    print("case2")
def tearDown(self):
    print("test end")

if name=="__main__":
#unittest.main()
suit=unittest.TestSuite
suit.addTest(Test_match("test_add"))
suit.addTest(Test_match("test_add2"))

runner = unittest.TextTestRunner()
runner.run(suit)

testsub_run.py
#coding=utf-8
import unittest
from match_ import Match
class TestMatchsub(unittest.TestCase):
def setUp(self):
print("test start:")
def tearDown(self):
print("test end")
def test_sub(self):
s=Match(6,2)
aa=s.sub()
self.assertEqual(aa,4)
print("case 1 test_sub")
def test_sub2(self):
s=Match(1,3)
aa=s.sub()
self.assertEqual(aa,-2)
print("case 2 test_sub2")

if name=="__main__":
#unittest.main()
suit=unittest.TestSuite
suit.addTest(TestMatchsub("test_sub"))
suit.addTest(TestMatchsub("test_sub2"))
runner=unittest.TextTestRunner()
runner.run(suit)
test_all.py
import unittest

test_dir = "./"
dd=unittest.defaultTestLoader.discover(test_dir,pattern="*run.py")

if name=="__main__":
runner = unittest.TextTestRunner()
runner.run(dd)
match_.py
from selenium import webdriver
class Match():
def init(self,a,b):
self.a=int(a)
self.b=int(b)

def add(self):
    su = self.a + self.b
    return su
    print(su)
def sub(self):
    return self.a-self.b

if name=="__main__":

c=Match()

dd=c.add(2,3)

print(dd)

总是no tests 为什么啊

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答