Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report collected results #9

Merged
merged 8 commits into from
Mar 18, 2023
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