I'm refactoring our test suite to take advantage of page object pattern. I'm missing how to structure the actual tests.
Lets say that I want to test StackOverflow posting and deleting. Once scenario may look like this:
Scenario 1: Posting Test
- Login
- Create a post
- Verify that the post is visible
Scenario 2: Removal test
- Login
- Create a post
- Remove the post
- Verify that the post is gone
My question:
The general guidelines for auto tests seem to be to have as few items asserted as possible. However, it is quite obvious that Scenario 1 and Scenario 2 are nearly identical and violate DRY. On the other hand, if I combine these two it's going to be difficult to understand the failures and perhaps the length with impact readability and ease of maintenance. Given that in real testing, there may be scenarios with dozens of overlapping steps, what is the best way of structuring them?
Edit:
Here's a blog post that describes a remarkably similar scenario and a potential solution. Briefly, the suggested solution is to create PostTest
class, and then inherit RemoveTest
class from it. This adheres to DRY, but I still have my doubts about this approach. If posting fails, both Posting test and Removal test will fail and produce noisy output (especially if tests are executed in random order). I'm still not sure this is better than a monolithic "Post & Remove" test.