Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-12182

Make gradebook classes testable and unit tests DB-independent

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.0
    • Fix Version/s: None
    • Component/s: Gradebook
    • Labels:
      None
    • Affected Branches:
      MOODLE_20_STABLE

      Description

      Gradebook Unit tests are currently using a set of test database tables, which are initialised before and stripped down after each test (over 300 of them). This is clunky, prone to inconsistencies with current code and DB schema, and extremely slow (tests complete at around 150 seconds).

      Proper unit testing should use mock objects and partial mocks, to isolate the methods being tested without getting into deep levels of external libraries and databases. The gradebook code is mostly ready for such tests, but a number of design choices make it impossible for complex methods. These include static method calls that eventually call on external library methods (especially database access methods); and calls to global functions (such as dmllib functions) which cannot be mocked.

      The proposed change is to :
      1. implement a singleton method within the grade_object method (get_instance), which can be used to access a class-wide static instance of each of the 5 gradebook classes when static methods need to be called on them (such as fetch and fetch_all).
      2. implement a lib_wrapper class which is defines methods with the same names and signatures as the global functions used by the gradebook classes, but which call these global functions directly. The gradebook classes, instead of calling the global functions themselves (get_records(...)), instantiate the lib_wrapper object and call its equivalent method. This makes it possible to use a mock lib_wrapper in the unit tests.

        Attachments

          Activity

            People

            • Assignee:
              andyjdavis Andrew Davis
              Reporter:
              nicolasconnault Nicolas Connault
              Participants:
              Component watchers:
              Jake Dallimore, Jun Pataleta, Ryan Wyllie
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: