[Java SDK] Search Attributes in TestWorkflowEnv Setup

I am getting error called:

Caused by: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: search attribute UserId is not defined

I am trying to add search attributes via:
private TestWorkflowEnvironment testEnv;

        testEnv.registerSearchAttribute("UserId", IndexedValueType.INDEXED_VALUE_TYPE_TEXT);

But its not working