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

Create TestSuite from TestCase #22

Merged
merged 6 commits into from
Mar 19, 2023

Conversation

kaiosilveira
Copy link
Owner

@kaiosilveira kaiosilveira commented Mar 19, 2023

Bonus: create a TestSuite from TestCase

Our goal is this chapter was to be able to create an instance of TestSuite from a TestCase class. This was implemented by using some reflection to extract all method names starting with the word test in the TestCase instance and then using it to create a slice of its own class for each test method, populating a TestSuite instance in each iteration. The result of this tricky computation was a TestCase.asSuite() method that returns a test suite instance containing all the test methods.

As a result of this approach, the name property ended up in a weird state, as it's now ignored sometimes due to the "outermost" TestCase instance returning a suite.

Closes #14

@kaiosilveira kaiosilveira force-pushed the bonus/create-testsuite-from-testcase branch 2 times, most recently from 2d69762 to 9d05a65 Compare March 19, 2023 13:41
Checklist:
- create TestSuite from TestCase 🎯
- collect test names in a TestCase 👈🏼

---

Output:
➜ python3 src/test_case_test.py
8 run, 1 failed
This class will be used just as a blank template so we can make sure our test method is being registred correctly.

Checklist:
- create TestSuite from TestCase 🎯
- collect test names in a TestCase 👈🏼

---

Output:
➜ python3 src/test_case_test.py
8 run, 1 failed
This method will be useful when creating multiple test cases out of a single one to create a test suite.

Checklist:
- create TestSuite from TestCase 🎯
- collect test names in a TestCase 👈🏼

---

Output:
➜ python3 src/test_case_test.py
8 run, 0 failed
Checklist:
- create TestSuite from TestCase 👈🏼
---

Output:
➜ python3 src/test_case_test.py
9 run, 1 failed
Checklist:
- create TestSuite from TestCase ✅

---

Output:
➜ python3 src/test_case_test.py
9 run, 0 failed
Checklist:
- create TestSuite from TestCase ✅
@kaiosilveira kaiosilveira force-pushed the bonus/create-testsuite-from-testcase branch from 9d05a65 to dd548a9 Compare March 19, 2023 13:42
@kaiosilveira kaiosilveira marked this pull request as ready for review March 19, 2023 13:44
@kaiosilveira kaiosilveira merged commit 3510abb into main 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.

Create TestSuite from TestCase
1 participant