最近翻了下写unit test 的文章,总结如下
What’s unit test?
“Unit testing is a software testing method by which individual units of source code.” – –Wikipedia
What’s integration test?
“Integration testing is the phase in software testing in which individual software modules are combined and tested as a group” – Wikipedia
Goal for unit test
- Defects obvious bugs
- Provide an example about how to call it
- Refactor
Effective way to find bugs
- Integration test
- Manual test
How to write good unit test?
Arrange -> Act -> Assert
# zoo.py
class Zoo:
def __init__(self, animals):
self.animals = animals
def sort_by_name(self):
self.animals = sorted(self.animals)
def get_animals(self):
return self.animals
# test_zoo.py
import unittest
class Zoo:
def __init__(self, animals):
self.animals = animals
def