Base Class for Data: What Belongs?


(Burdette) #1

The test automation core comprises all of the domain-independent framework code – that is, all the code that might be used for testing in any domain.

For almost any domain-specific testing, there will be domain-specific data objects (users, agents, whatever). For a REST API, for example, each resource would be represented by a data object.

Because the core should do as much of the heavy lifting as possible, it should support data classes with a base class for data.

Question: What do you think belongs in the base class for data?

In my GitHub project, RubyTest, there’s a core BaseClassForData that has a handful of methods for all data classes inherit.

Here’s what I have:

initialize(fields, values)

Instantiates the data object:

  • fields is an array of field names.
  • values is a hash of name/value pairs for initializing some or all of the fields.

log(log, section_name = self.class.name)

Logs the data object (field names and values):

  • log is the Log object.
  • section_name is the name of the log section that will be created to contain the data.

The logging is recursive: if a field in the data object contains another data object, that object is also logged (in a nested section).

self.equal?(expected_obj, actual_obj, fields_to_ignore = [])

Determines whether two data objects are equal:

  • expected_obj and actual_obj are the data objects to compare.
  • fields_to_ignore is an array of fields to be excluded from the comparison.

The comparison is recursive: if a field in the data object contains another data object, that object is also compared.

self.verdict_equal?(log, verdict_id, expected_obj, actual_obj, message = nil)

Logs expected and actual values for each field, and whether the two values are equal:

  • log is the Log object.
  • verdict_id is the verdict identifier.
  • expected_obj and actual_obj are the objects to be compared.
  • message is an optional message string.

The verification is recursive: if a field in the data object contains another data object, that object is also verified.

verdict_valid?(log, verdict_id)

Logs the value for each field in the data object, and whether the value is valid (i.e., in the correct form):

  • log is the Log object.
  • verdict_id is the verdict identifier.

The validation is recursive: if a field in the data object contains another data object, that object is also validated.

to_hash

Returns the data object’s field names/values as a hash.

The hashing is recursive: if a field in the data object contains another data object, that object becomes a nested hash.