Created
May 18, 2016 17:42
-
-
Save arvinwiyono/f40fcd633aab5dcf7011255762cb476f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User: | |
def __init__(self, name): | |
self.name = name | |
def get_name(self): | |
return self.name | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from unittest.mock import Mock, patch | |
from user import User | |
class MockUpTest(unittest.TestCase): | |
def test_get_name(self): | |
mock_user = Mock(spec=User) | |
mock_obj = mock_user() | |
mock_obj.get_name.return_value = "Biondi" | |
self.assertEqual(mock_obj.get_name(), "Biondi") | |
@patch("user.User.get_name") | |
def test_get_name(self, mock_user): | |
mock_user.return_value = "Biondi" | |
self.assertEqual(User("Arvin").get_name(), "Biondi") | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment