Edgewall Software

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 MockRequest.

API Changes:

Added MockRequest class to trac.test.

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)

comment:1 by Ryan J Ollos, 9 years ago

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.

in reply to:  1 comment:2 by Ryan J Ollos, 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:

  1. Create helper functions in trac.test.
  2. 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).
  3. 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 TestCases.

comment:3 by Ryan J Ollos, 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:4 by Ryan J Ollos, 8 years ago

comment:3 changes committed in [14535].

comment:5 by Ryan J Ollos, 8 years ago

Proposed changes in log:rjollos.git:t12211_mock_request. I'll add class documentation before committing.

comment:6 by Christian Boos, 8 years ago

Very nice indeed (both TicketTestCase and MockRequest).

comment:7 by Ryan J Ollos, 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 Ryan J Ollos, 8 years ago

I modified MockRequest to use Request as a base class and populate the callbacks: log:rjollos.git:t12211_mock_request.1.

comment:9 by Ryan J Ollos, 8 years ago

API Changes: modified (diff)
Milestone: next-major-releases1.0.11
Owner: set to Ryan J Ollos
Release Notes: modified (diff)
Status: newassigned
Note: See TracTickets for help on using tickets.