Skip to main content
Question

Faking a system language in a unit test

  • April 21, 2026
  • 1 reply
  • 14 views

SanderAdam
Captain
Forum|alt.badge.img+6

Hello everyone, 

We have a unit test where we want to check if the right value (either Dutch or English) is returned from the tsf_translate function. We set this value via a default, upon opening the right (help)text is shown to the user, in the right language. We want to unit test this, but how can I fake the Dutch system language in a unit test?

I found a question that provided the following code:
 

EXEC [sys].[sp_set_session_context] @key = 'tsf_appl_lang_id'
,@value = 'nl-NL'
,@read_only = 0;

and that gave the following error:
 

Is it possible to fake the system language? I can use it for English, as it always falls back to English, but I also want to unit test if it gives the Dutch values.

1 reply

Renée Evertzen
Moderator
Forum|alt.badge.img+4

Hello ​@SanderAdam,

It is a bit hard to tell with the context that you have provided to see where from you are executing your code example from within a unit test preparation query or elsewhere, but I’ll go with the assumption that it is part of the unit test itself through a preparation query. 

I also expect that this the reason why you are not allowed to overide the key for the appl_lang_id.  Session context is scoped per connection and it has most likely already been set in the session context as read only. Once a key is set as read-only, you can't override it in the same session. So trying to force ‘nl-NL’ with sp_set_session_context after it's already been initialized won't work. 

I believe this function is part of the Translating model objects in business logic Thinkstore solution? Perhaps it would be useful to look into whether the function could be set up differently so it can be tested properly, but as it is now I think there is not much you can do, unfortunately. 

Kind regards, 
Renée