One hot encoding is a way of converting output label for 3 categories like 2 into [0, 1, 0] or 3 into [0, 0, 1].
If you are using scikit learn to convert the value into one hot encoder then in training time you should use
enc = OneHotEncoder()
If you are using scikit learn to convert the value into one hot encoder then in testing time you should use
The reason we are using transform function in case of testing is we have to consider the label values on the basis of which we have converted data in training time. Because in testing time we not get all labels for that column