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

Implement tearDown() #8

Merged
merged 11 commits into from
Mar 18, 2023
Merged

Implement tearDown() #8

merged 11 commits into from
Mar 18, 2023

Conversation

kaiosilveira
Copy link
Owner

@kaiosilveira kaiosilveira commented Mar 18, 2023

Chapter 20: Cleaning up after

Our goal in this chapter was to implement some form of clean-up mechanism so our tests always start from a clean slate. Our approach here was to introduce a tearDown() method to be called after the test method was run.

Implementation checklist:

Invoke tearDown afterward
☑️ Invoke tearDown even if the test method fails
☑️ Run multiple tests
☑️ Report collected results
Log string in WasRun

Closes #6

This field will be used to make sure the tests ran in a specific order (specially setUp and tearDown).

Checklist:
- Invoke tearDown afterward 🎯
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results
- Log string in WasRun 👈🏼
Checklist:
- Invoke tearDown afterward 🎯
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results
- Log string in WasRun 👈🏼
Checklist:
- Invoke tearDown afterward 🎯
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results
- Log string in WasRun 👈🏼
Checklist:
- Invoke tearDown afterward 🎯
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results
- Log string in WasRun 👈🏼

---

Output:
➜ python3 src/test_case_test.py
Traceback (most recent call last):
  File "tdd-xunit-example/src/test_case_test.py", line 19, in <module>
    TestCaseTest("testSetup").run()
  File "tdd-xunit-example/src/test_case.py", line 12, in run
    method()
  File "tdd-xunit-example/src/test_case_test.py", line 15, in testSetup
    assert ("setUp " == self.test.log)
            ^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
Checklist:
- Invoke tearDown afterward 🎯
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results
- Log string in WasRun 👈🏼
Checklist:
- Invoke tearDown afterward 🎯
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results
- Log string in WasRun 👈🏼
Checklist:
- Invoke tearDown afterward 🎯
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results
- Log string in WasRun 👈🏼
We are now using it only to configure WasRun, which is in use only in one place, so it's better to just get rid of this extra boilerplate.

Checklist:
- Invoke tearDown afterward 🎯
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results
- Log string in WasRun ✅
Checklist:
- Invoke tearDown afterward 👈🏼🎯
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results
- Log string in WasRun ✅

---

Output:
➜ python3 src/test_case_test.py
Traceback (most recent call last):
  File "tdd-xunit-example/src/test_case_test.py", line 12, in <module>
    TestCaseTest("testTemplateMethod").run()
  File "tdd-xunit-example/src/test_case.py", line 12, in run
    method()
  File "tdd-xunit-example/src/test_case_test.py", line 9, in testTemplateMethod
    assert ("setUp testMethod tearDown " == test.log)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
Checklist:
- Invoke tearDown afterward 👈🏼🎯
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results
- Log string in WasRun ✅

---

Output:
➜ python3 src/test_case_test.py
Traceback (most recent call last):
  File "tdd-xunit-example/src/test_case_test.py", line 12, in <module>
    TestCaseTest("testTemplateMethod").run()
  File "tdd-xunit-example/src/test_case.py", line 13, in run
    self.tearDown()
    ^^^^^^^^^^^^^
AttributeError: 'TestCaseTest' object has no attribute 'tearDown'
Checklist:
- Invoke tearDown afterward ✅
- Invoke tearDown even if the test method fails
- Run multiple tests
- Report collected results
- Log string in WasRun ✅
@kaiosilveira kaiosilveira marked this pull request as ready for review March 18, 2023 13:42
@kaiosilveira kaiosilveira merged commit a596efa into main Mar 18, 2023
@kaiosilveira kaiosilveira changed the title implement tearDown() Implement tearDown() Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chapter 20: Cleaning up after
1 participant