java - change default locale for junit test -


how change default locale junit test. current locale en. want test es_es. tried:

system.setproperty("locale", "es_es"); 

but doesn't seem work.

you can set default locale locale.setdefault.

sets default locale instance of java virtual machine. not affect host locale.

locale.setdefault(new locale("es", "es")); 

testing following resource files:

  • test.properties

    message=yes 
  • test_es_es.properties

    message=sí 

here main function, no change default locale (en_us):

public static void main(string[] args) {     resourcebundle test = resourcebundle.getbundle("test");     system.out.println(test.getstring("message")); } 

output:

yes 

here main function, change test locale (es_es):

public static void main(string[] args) {     locale.setdefault(new locale("es", "es"));     resourcebundle test = resourcebundle.getbundle("test");     system.out.println(test.getstring("message")); } 

output:

this should work when applied junit test case.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -