private static void prepareDriverContext(DriverContext driverContext) {
    // mock the queryType and operation, because the calculation if those are quite complicated,
    // which should be unit tested separately
    when(driverContext.getQueryType()).thenReturn(DummyRecord.QUERY_TYPE);
    driverContext.setQueryErrorMessage(DummyRecord.FAILURE_REASON);
    driverContext.setExplainPlan(DummyRecord.PLAN);
    FetchTask fetchTask = mock(FetchTask.class);
    when(fetchTask.getNumRows()).thenReturn(DummyRecord.NUM_ROWS_FETCHED);
    when(driverContext.getFetchTask()).thenReturn(fetchTask);

    QueryProperties queryProperties = mock(QueryProperties.class);
    when(queryProperties.getUsedTables()).thenReturn(DummyRecord.USED_TABLES);
    when(driverContext.getQueryProperties()).thenReturn(queryProperties);
  }
This unit test asserts that the record is created as expected from the various hive source objects like:
DriverContext, SessionState, QueryInfo, etc.
itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/queryhistory/TestQueryHistoryService.java