vijayjcp / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 2 forks source link

While using powermock properties file(conf.properties) not loaded #428

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. create a sample class 1, create a config file and try to load the config 
file(*.properties) values inside the sample method A. create a new class 2 and 
method 2.B. Call 1.A from B. Create another method C and call 2.B from 2.C
2. Using Powermock mock A's behaviour and try to test C.
3. The property files which needs to be loaded are not loaded as expected. 
Getting nulll for property variable

What is the expected output? What do you see instead?
need to load the property file. But this is not happening with following code. 
InputStream in = 
Thread.currentThread().getContextClassLoader().getResourceAsStream("conf.propert
ies"); seems to be a issue with powermock custom class loader couldnt find this 
property file or property utils file to load the property. how to override 
powermock class loading for property loading alone, then i continue to mock the 
desired mock needed classes.

What version of the product are you using? On what operating system?
windows OS, eclipse IDE(test is working fine in IDE) and ant build. thsi is 
maven compatible java project. Using Junit 4. eclipse indigo.

Please provide any additional information below.
when i remove the @preparefortest statement alone things are working fine. Also 
not that we are running junit as a suite. in mastersuiterunner.java we call 
baseclass(junit test class) JFPTestBase.java there we have @preparefortest. 
when we remove that alone thing are working fine.but then we couldnt use 
mocking if we remove. (we didnt remove @runwith)

Original issue reported on code.google.com by sashivij...@gmail.com on 3 Feb 2013 at 11:11

GoogleCodeExporter commented 8 years ago
im the owner of this issue -- small correction here 
What version of the product are you using? On what operating system?
windows OS, eclipse IDE(test is working fine in eclipse IDE),
BUT NOT WORKING in ant build. 
This is maven compatible java project. 
Using Junit 4. eclipse indigo. 

Original comment by sashivij...@gmail.com on 3 Feb 2013 at 11:13

GoogleCodeExporter commented 8 years ago
I am facing the exact issue. The MockClassLoader loads the property file form 
jar in classpath if run from eclipse IDE. But when i run it from Ant, the 
property file is not found. Looking forward to the solution.

Original comment by pankaj.t...@gmail.com on 3 Feb 2013 at 2:34

GoogleCodeExporter commented 8 years ago
Thanks pankaj for ur post....actually we have the property file seperately 
only...not included in jar....we can run in eclipse IDE but not in ant when 
running in ant. the variable which stores property file load is returning 
null..I will shortly and definitely update the code snippet for ease of 
understanding. But as of now if any light is thrown upon this . it will be 
really helpful. Thanks in advance.

Original comment by sashivij...@gmail.com on 3 Feb 2013 at 4:30

GoogleCodeExporter commented 8 years ago
Hi Everyone. Finally found a solution for my issue. in Ant task for junit fork 
value needs to be set as true, when setting fork as true(or Yes) properties 
file is loaded successfully. previously i had fork as "false". 
Also I thought of trying to use Junit 3.xx jar for ant build. As eclipse uses 
junti 3 for IDE level testing. But first try with fork= "true" worked out. 

Original comment by sashivij...@gmail.com on 4 Feb 2013 at 3:25

GoogleCodeExporter commented 8 years ago
Thanks for the update. I will try with fork=true and will update here.

Original comment by pankaj.t...@gmail.com on 4 Feb 2013 at 10:56