---
title: "change default locale for junit test"  
description: "change default locale for junit test"  
author: "Anonymous User"  
published: 2014-12-29  
updated: 2014-12-30  
canonical: https://www.mindstick.com/forum/12827/change-default-locale-for-junit-test  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# change default locale for junit test

How do you change the [default](https://www.mindstick.com/interview/12771/what-is-the-importance-of-default-resources) [locale](https://www.mindstick.com/interview/2482/what-is-locale) for a JUnit [Test](https://yourviews.mindstick.com/story/1427/explosive-facts-about-trinity-test-world-s-first-nuclear-bomb). Current locale is en. I want to test for es_ES. I tried:\
System.setProperty("locale", "es_ES");But this doesn't seem to work.

## Replies

### Reply by Mark Devid

You can set the default Locale with Locale.setDefault.\
Sets the default locale for this instance of the Java Virtual Machine. This does not affect the host locale.\
Locale.setDefault(new Locale("es", "ES"));Testing with the following resource files:\
test.properties\
message=Yestest_es_ES.properties\
message=SíHere is my main function, with no change to my default locale (en_US):\

```
public static void main(String[] args){    ResourceBundle test = ResourceBundle.getBundle("test");    System.out.println(test.getString("message"));}
```

**Output:**\
YesHere is my main function, with a change to your 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 to a JUnit test case.


---

Original Source: https://www.mindstick.com/forum/12827/change-default-locale-for-junit-test

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
