Unit test the printCurrentDate function.
- Test the code with doubles from a library.
- Test the code with doubles created by you.
class PrintDate:
def __init__(self, calendar, printer):
self.printer = printer
self.calendar = calendar
def print_current_date(self):
self.printer.print_line(self.calendar.today())
How to build a Mock and Stub manually.
How to use Unittest Mock to generate the doubles.
def test_should_send_an_email(self):
emailSender = Mock(EmailSender)
user_registration = UserRegistration(email_sender)
user_registration.register()
email_sender.send.assert_called()
def test_should_success_when_password_is_valid(self):
password_validator = Mock(PasswordValidator)
password_validator.is_valid = Mock(return_value=true)
user_registration = UserRegistration(password_validator)
success = user_registration.register()
assertTrue(success)
Run the tests
make tests
Run the code coverage
make coverage
Open the Makefile and copy and paste the lines below each command.
Generate the image
make docker-build
Run the tests
make docker-tests
Run the code coverage
make docker-coverage
Open the Makefile and copy and paste the lines below each command.
Luis Rovirosa @luisrovirosa
Jordi Anguela @jordianguela