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:
sí
this should work when applied junit test case.
Comments
Post a Comment