Skip to content

Commit

Permalink
#9 Report collected results
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiosilveira authored Mar 18, 2023
2 parents a596efa + 47adee2 commit c5ffa61
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/test_case.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from test_result import TestResult


class TestCase:

def __init__(self, name) -> None:
Expand All @@ -7,10 +10,13 @@ def setUp(self) -> None:
pass

def run(self) -> None:
result = TestResult()
result.testStarted()
self.setUp()
method = getattr(self, self.name)
method()
self.tearDown()
return result

def tearDown(self) -> None:
pass
10 changes: 8 additions & 2 deletions src/test_case_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
class TestCaseTest(TestCase):
def testTemplateMethod(self) -> None:
test = WasRun("testMethod")
test.run()
assert ("setUp testMethod tearDown " == test.log)
result = test.run()
assert ("1 run, 0 failed" == result.summary())

def testFailedResult(self) -> None:
test = WasRun("testBrokenMethod")
result = test.run()
assert ("1 run, 1 failed" == result.summary())


TestCaseTest("testTemplateMethod").run()
TestCaseTest("testFailedResult").run()
9 changes: 9 additions & 0 deletions src/test_result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class TestResult:
def __init__(self) -> None:
self.runCount = 0

def testStarted(self) -> None:
self.runCount = self.runCount + 1

def summary(self):
return "%d run, 0 failed" % self.runCount
3 changes: 3 additions & 0 deletions src/was_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ def testMethod(self) -> None:

def tearDown(self) -> None:
self.log = self.log + "tearDown "

def testBrokenMethod(self) -> None:
raise Exception

0 comments on commit c5ffa61

Please sign in to comment.