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

Make gradebook classes testable and unit tests DB-independent

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Major Major
    • None
    • 2.0
    • Gradebook
    • None
    • MOODLE_20_STABLE

      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.

            andyjdavis Andrew Davis
            nicolasconnault Nicolas Connault (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.