Skip to content

Commit 04190cb

Browse files
author
Florian Kromer
committed
change: improve comments / remove: obsolete single file test invocation
1 parent 882e663 commit 04190cb

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

dft/constructor_injection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"""
66
Port of the Java example of "Constructor Injection" in
77
"xUnit Test Patterns - Refactoring Test Code" by Gerard Meszaros
8-
(ISBN-10: 0131495054, ISBN-13: 978-0131495050)
8+
(ISBN-10: 0131495054, ISBN-13: 978-0131495050) accessible in outdated version on
9+
http://xunitpatterns.com/Dependency%20Injection.html.
910
1011
production code which is untestable:
1112

tests/test_constructor_injection.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
"""
88
Port of the Java example of "Constructor Injection" in
99
"xUnit Test Patterns - Refactoring Test Code" by Gerard Meszaros
10-
(ISBN-10: 0131495054, ISBN-13: 978-0131495050)
10+
(ISBN-10: 0131495054, ISBN-13: 978-0131495050) accessible in outdated version on
11+
http://xunitpatterns.com/Dependency%20Injection.html.
1112
1213
Test code which will almost always fail (if not exactly 12:01) when untestable
13-
production code (production code time provider is datetime) is used:
14+
production code (have a look into constructor_injection.py) is used:
1415
1516
def test_display_current_time_at_midnight(self):
1617
class_under_test = TimeDisplay()
@@ -23,7 +24,8 @@ class ConstructorInjectionTest(unittest.TestCase):
2324

2425
def test_display_current_time_at_midnight(self):
2526
"""
26-
Will almost always fail (despite of right at/after midnight).
27+
Would almost always fail (despite of right at/after midnight) if
28+
untestable production code would have been used.
2729
"""
2830
time_provider_stub = MidnightTimeProvider()
2931
class_under_test = TimeDisplay(time_provider_stub)
@@ -32,16 +34,11 @@ def test_display_current_time_at_midnight(self):
3234

3335
def test_display_current_time_at_current_time(self):
3436
"""
35-
Just as justification for working example. (Will always pass.)
37+
Just as justification for working example with the time provider used in
38+
production. (Will always pass.)
3639
"""
3740
production_code_time_provider = ProductionCodeTimeProvider()
3841
class_under_test = TimeDisplay(production_code_time_provider)
3942
current_time = datetime.datetime.now()
4043
expected_time = "<span class=\"tinyBoldText\">" + str(current_time.hour) + ":" + str(current_time.minute) + "</span>"
4144
self.assertEqual(class_under_test.get_current_time_as_html_fragment(), expected_time)
42-
43-
if __name__ == "__main__":
44-
# PYTHONPATH=$PYTHONPATH:~/ws_github/python-patterns/
45-
# export PYTHONPATH
46-
# python tests/test_constructor_injection.py
47-
unittest.main()

0 commit comments

Comments
 (0)