gordonad / powermock

Automatically exported from code.google.com/p/powermock
0 stars 0 forks source link

Investigate if mock policies fails when applied in a test suite #191

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
From phatblat:

I have a few related test classes running great under the
PowerMockRunner but today I threw them together into a JUnit4 suite
and am finding that the Log4jMockPolicy  I have applied to them is not
being honored. The tests still run and pass, the mock policy just
suppresses the following distracting errors:

log4j:ERROR A "org.apache.log4j.xml.DOMConfigurator" object is not
assignable to a "org.apache.log4j.spi.Configurator" variable.
log4j:ERROR The class "org.apache.log4j.spi.Configurator" was loaded
by
log4j:ERROR [org.powermock.core.classloader.MockClassLoader@11121f6]
whereas object of type
log4j:ERROR "org.apache.log4j.xml.DOMConfigurator" was loaded by
[sun.misc.Launcher$AppClassLoader@92e78c].
log4j:ERROR Could not instantiate configurator
[org.apache.log4j.xml.DOMConfigurator].

I thought this issue might have been related to the hierarchy of my
test class setup. I have an abstract base class which has all the mock
construction and PowerMock class-level annotations. The test
subclasses have no class-level annotations. I have experimented with
moving the @MockPolicy(Log4jMockPolicy.class) annotation to the
subclasses with no change in behavior, I still get the above errors
which mean the policy is not being applied. If any of the other
PowerMock annotations were not being picked up the tests would
certainly fail.

Below is a summary of the classes involved (each defined in own file,
class body removed for brevity):

@RunWith(Suite.class)
@SuiteClasses( { HCUploaderManagerImplReconciliationTest.class,
HCUploaderManagerImplDupsInEnteredStateTest.class })
public class HCUploaderManagerTestSuite {}

@RunWith(PowerMockRunner.class)
@PrepareForTest(BusinessManagerImpl.class)
@SuppressStaticInitializationFor
("com.company.business.BusinessManagerImpl")
@MockPolicy(Log4jMockPolicy.class)
public class HCUploaderManagerImplAbstractTest {...}

public class HCUploaderManagerImplReconciliationTest extends
HCUploaderManagerImplAbstractTest {...}

public class HCUploaderManagerImplDupsInEnteredStateTest extends
HCUploaderManagerImplAbstractTest {...}

My question is whether I have set up this test suite incorrectly or
does PowerMock not currently support mock policies when run within a
test suite?

Original issue reported on code.google.com by johan.ha...@gmail.com on 3 Nov 2009 at 8:12

GoogleCodeExporter commented 9 years ago

Original comment by johan.ha...@gmail.com on 22 Jul 2010 at 9:20