I am creating a Java unit test to test some code I recently changed. However, the method I am testing instantiates a class which uses ResourceBundle …
ResourceBundle.getBundle("businessVariables").getString("product.name"));
The resource file lives in the web package at Mycompany_web/src/main/webapp/WEB-INF/classes/businessVariables.properties
My test lives in my xml package at Mycompany_xml/src/test/java/uk/co/mycompany/xmlapi/RequestProcessorTestNew.java
During normal runtime the resource bundle is accessible, but not when my unit test is run. It throws this error …
Testcase: testCreateInitialStatusResponse(uk.co.mycompany.xmlapi.RequestProcessorTestNew): Caused an ERROR
null
java.lang.reflect.InvocationTargetException
at uk.co.mycompany.xmlapi.RequestProcessorTestNew.testCreateInitialStatusResponse(RequestProcessorTestNew.java:62)
Caused by: java.lang.ExceptionInInitializerError
at uk.co.mycompany.xmlapi.RequestProcessorImpl.createInitialStatusResponse(RequestProcessorImpl.java:812)
Caused by: java.util.MissingResourceException: Can't find bundle for base name businessVariables, locale en_US
What should I do? Can I enable my test to see the resource bundle somehow? Can I create a mock resource file somewhere which somehow the code will be able to see?
en_Us
locale? see #2083659 – Balbriggan/webapp/WEB-INF/classes
seems like a the target folder. Look into your project structure - the bundle file would better be in e.g.Mycompany_web/src/main/resources/businessVariables.properties
– Balbriggan