private TezTask generateTezTask() {
    TezTask tezTask = new TezTask();

    TezRuntimeContext runtimeContext = tezTask.getRuntimeContext();

    TezSessionState tezSessionState = mock(TezSessionState.class);
    when(tezSessionState.getAppMasterUri()).thenReturn(DummyRecord.TEZ_AM_ADDRESS);
    runtimeContext.init(tezSessionState);

    runtimeContext.setDagId(DummyRecord.DAG_ID);
    runtimeContext.setApplicationId(DummyRecord.TEZ_APPLICATION_ID);
    runtimeContext.setSessionId(DummyRecord.TEZ_SESSION_ID);
    runtimeContext.setExecutionMode(DummyRecord.EXECUTION_MODE);

    TezJobMonitor monitor = mock(TezJobMonitor.class);
    LogHelper console = mock(LogHelper.class);
    when(monitor.logger()).thenReturn(console);
    when(console.getQuerySummary()).thenReturn(DummyRecord.EXEC_SUMMARY);
    runtimeContext.setMonitor(monitor);

    TezCounters counters = new TezCounters();
    runtimeContext.setCounters(counters);
    counters.findCounter(DAGCounter.class.getName(), DAGCounter.TOTAL_LAUNCHED_TASKS.name())
        .setValue(DummyRecord.TOTAL_LAUNCHED_TASKS);
    counters.findCounter(DAGCounter.class.getName(), DAGCounter.NUM_SUCCEEDED_TASKS.name())
        .setValue(DummyRecord.NUM_SUCCEEDED_TASKS);
    counters.findCounter(DAGCounter.class.getName(), DAGCounter.NUM_KILLED_TASKS.name())
        .setValue(DummyRecord.NUM_KILLED_TASKS);
    counters.findCounter(DAGCounter.class.getName(), DAGCounter.NUM_FAILED_TASKS.name())
        .setValue(DummyRecord.NUM_FAILED_TASKS);
    counters.findCounter(DAGCounter.class.getName(), DAGCounter.WALL_CLOCK_MILLIS.name())
        .setValue(DummyRecord.TASK_DURATION_MILLIS);
    counters.findCounter(DAGCounter.class.getName(), DAGCounter.NODE_USED_COUNT.name())
        .setValue(DummyRecord.NODE_USED_COUNT);
    counters.findCounter(DAGCounter.class.getName(), DAGCounter.NODE_TOTAL_COUNT.name())
        .setValue(DummyRecord.NODE_TOTAL_COUNT);
    counters.findCounter(TaskCounter.class.getName(), TaskCounter.REDUCE_INPUT_GROUPS.name())
        .setValue(DummyRecord.REDUCE_INPUT_GROUPS);
    counters.findCounter(TaskCounter.class.getName(), TaskCounter.REDUCE_INPUT_RECORDS.name())
        .setValue(DummyRecord.REDUCE_INPUT_RECORDS);
    counters.findCounter(TaskCounter.class.getName(), TaskCounter.SPILLED_RECORDS.name())
        .setValue(DummyRecord.SPILLED_RECORDS);
    counters.findCounter(TaskCounter.class.getName(), TaskCounter.NUM_SHUFFLED_INPUTS.name())
        .setValue(DummyRecord.NUM_SHUFFLED_INPUTS);
    counters.findCounter(TaskCounter.class.getName(), TaskCounter.NUM_FAILED_SHUFFLE_INPUTS.name())
        .setValue(DummyRecord.NUM_FAILED_SHUFFLE_INPUTS);
    counters.findCounter(TaskCounter.class.getName(), TaskCounter.INPUT_RECORDS_PROCESSED.name())
        .setValue(DummyRecord.INPUT_RECORDS_PROCESSED);
    counters.findCounter(TaskCounter.class.getName(), TaskCounter.INPUT_SPLIT_LENGTH_BYTES.name())
        .setValue(DummyRecord.INPUT_SPLIT_LENGTH_BYTES);
    counters.findCounter(TaskCounter.class.getName(), TaskCounter.OUTPUT_RECORDS.name())
        .setValue(DummyRecord.OUTPUT_RECORDS);
    counters.findCounter(TaskCounter.class.getName(), TaskCounter.OUTPUT_BYTES_PHYSICAL.name())
        .setValue(DummyRecord.OUTPUT_BYTES_PHYSICAL);
    counters.findCounter(TaskCounter.class.getName(), TaskCounter.SHUFFLE_CHUNK_COUNT.name())
        .setValue(DummyRecord.SHUFFLE_CHUNK_COUNT);
    counters.findCounter(TaskCounter.class.getName(), TaskCounter.SHUFFLE_BYTES.name())
        .setValue(DummyRecord.SHUFFLE_BYTES);
    counters.findCounter(TaskCounter.class.getName(), TaskCounter.SHUFFLE_BYTES_DISK_DIRECT.name())
        .setValue(DummyRecord.SHUFFLE_BYTES_DISK_DIRECT);
    counters.findCounter(TaskCounter.class.getName(), TaskCounter.SHUFFLE_PHASE_TIME.name())
        .setValue(DummyRecord.SHUFFLE_PHASE_TIME);
    counters.findCounter(TaskCounter.class.getName(), TaskCounter.MERGE_PHASE_TIME.name())
        .setValue(DummyRecord.MERGE_PHASE_TIME);

    return tezTask;
  }
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