-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtest_example.py
More file actions
42 lines (33 loc) · 1011 Bytes
/
Copy pathtest_example.py
File metadata and controls
42 lines (33 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
example.py 的测试用例
"""
import unittest
from example import MyClass, bad_function
class TestExample(unittest.TestCase):
"""测试example.py中的类和函数"""
def test_myclass_init(self):
"""测试MyClass初始化"""
obj = MyClass()
self.assertEqual(obj.name, "")
self.assertEqual(obj.age, 0)
def test_myclass_set_name(self):
"""测试set_name方法"""
obj = MyClass()
obj.set_name("张三")
self.assertEqual(obj.name, "张三")
def test_myclass_get_info(self):
"""测试get_info方法"""
obj = MyClass()
obj.set_name("李四")
obj.age = 25
info = obj.get_info()
self.assertIn("李四", info)
self.assertIn("25", info)
def test_bad_function(self):
"""测试bad_function函数"""
result = bad_function()
self.assertEqual(result, 3)
if __name__ == "__main__":
unittest.main()