@Before
  public void setUp() throws Exception {


    // create and put .hiverc sample file to default directory
    initFile = File.createTempFile("test", "hive");
    tmpDir =
        initFile.getParentFile().getAbsoluteFile() + File.separator
            + "TestSessionGlobalInitFile";
    initFile.delete();
    FileUtils.deleteDirectory(new File(tmpDir));

    initFile =
        new File(tmpDir + File.separator + SessionManager.HIVERCFILE);
    initFile.getParentFile().mkdirs();
    initFile.createNewFile();

    String[] fileContent =
        new String[] { "-- global init hive file for test", "set a=1;",
            "set hiveconf:b=1;", "set hivevar:c=1;", "set d\\", "      =1;",
            "add jar " + initFile.getAbsolutePath() };
    FileUtils.writeLines(initFile, Arrays.asList(fileContent));

    // set up service and client
    hiveConf = new HiveConf();
    hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_GLOBAL_INIT_FILE_LOCATION,
        initFile.getParentFile().getAbsolutePath());
    hiveConf
    .setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER,
        "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory");
    service = new FakeEmbeddedThriftBinaryCLIService(hiveConf);
    service.init(new HiveConf());
    client = new ThriftCLIServiceClient(service);
  }
This class is almost the same as EmbeddedThriftBinaryCLIService,
except its constructor having a HiveConf param for test usage.
service/src/test/org/apache/hive/service/cli/session/TestSessionGlobalInitFile.java