Opened 9 years ago
Last modified 6 years ago
#12211 closed enhancement
Base test case classes with helper methods — at Version 9
Reported by: | Ryan J Ollos | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | normal | Milestone: | 1.0.11 |
Component: | general | Version: | |
Severity: | normal | Keywords: | test |
Cc: | Branch: | ||
Release Notes: |
Refactored test cases to use |
||
API Changes: |
Added |
||
Internal Changes: |
Description
I've been considering ways to reduce the code duplication of helper methods in the test code. For example, there are at least a half-dozen instances of _insert_ticket
and _create_request
. One possibility would be to create a mixin-like base class with the helper methods.
Change History (9)
follow-up: 2 comment:1 by , 9 years ago
comment:2 by , 8 years ago
Replying to Ryan J Ollos:
I'm very interested to know if someone sees a better way to do this.
I've considered a few alternative approaches:
- Create helper functions in
trac.test
. - Create helper class(es) in
trac.test
. The classes could be instantiated as needed in test cases. This would minimize the number of methods relative to approach (1). - Attach the helper functions to
trac.test.EnvironmentStub
. One downside is that the number of methods on the class could grow large very quickly.
My main aim for this ticket is to find an approach that avoids defining _create_request
on numerous TestCase
s.
comment:3 by , 8 years ago
Replaced uses of _insert_user
with EnvironmentStub.insert_known_users
in [14524]. Additional proposed changes in log:rjollos.git:t12211_known_users. insert_known_users
was added in 1.1.x, so it wouldn't be a breaking API change to rename the method.
Continuing the thought in comment:2, it might make sense to define insert_users
on a class other than EnvironmentStub
.
comment:5 by , 8 years ago
Proposed changes in log:rjollos.git:t12211_mock_request. I'll add class documentation before committing.
comment:7 by , 8 years ago
Thanks, I added TicketTestCase
to the changes ([9763655/rjollos.git]) and I'll spend more time reviewing the code in trac.ticket.tests
to see what other methods can be added to the class.
comment:8 by , 8 years ago
I modified MockRequest
to use Request
as a base class and populate the callbacks: log:rjollos.git:t12211_mock_request.1.
Example of changes I have in mind can be found in log:rjollos.git:t12211_base_test_classes. I'm very interested to know if someone sees a better way to do this.