Why does it not need to set test group when using 'rank:pairwise' in xgboost?
The output is a score that can be used to rank the samples, and the point in this sort of ranking problem is that you'll only care about ranking samples within the same group (which you think of as being results from a given query).  

But that can be safely left to you on the testing set.  (Indeed, you might as well only run the prediction for each group separately.  You might think about the output in your case as assuming that the test set is all from a single query.)  For scoring on the test set, it might matter what the specified groups are, but not for just making predictions.

For training, the group data is needed so the algorithm knows not to calibrate the rankings for intergroup comparisons.

See also:
How fit pairwise ranking models in xgBoost?
https://github.com/dmlc/xgboost/blob/master/doc/tutorials/input_format.rst#group-input-format