PowerMock tests work fine in Eclipse, but don't execute in Maven build

1,933 views
Skip to first unread message

KARR, DAVID

unread,
Jan 20, 2013, 6:49:31 PM1/20/13
to powe...@googlegroups.com
I normally use Mockito with Maven. I'm trying to write some tests using PowerMock. I got the PowerMock test working fine in Eclipse, but now I'm noticing that the test is not running in the Maven build. Maven finds the test class, but it seems to think there are no tests. It's also trying to run it with TestNG instead of JUnit, which is surprising.

This is the build output I see:
----------------------
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.foo.tv.client.UiFeatureManagerTest
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@76cbf7
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.69 sec

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
---------------------------

My very elided test class looks like this:
------------------------
@RunWith(PowerMockRunner.class)
@PrepareForTest({...})
public class UiFeatureManagerTest {

private UiFeatureManager uiFeatureManager;

...

@Before
public void setup() {
uiFeatureManager = new UiFeatureManager(...);
...
PowerMockito.mockStatic(Blio.class, OrderUtil.class);
}

@Test
public void lookupstuff() {
when(...).thenReturn(...);
...
}
-------------------

This is my entire POM:
-----------------------------
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>powermockdemo</groupId>
<artifactId>powermockdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<failIfNoTests>true</failIfNoTests>
<parallel>methods</parallel>
<detail>true</detail>
<additionalClasspathElements>
<additionalClasspathElement>src/test/resources</additionalClasspathElement>
<additionalClasspathElement>${project.build.directory}/classes</additionalClasspathElement>
<additionalClasspathElement>${project.build.directory}/test-classes</additionalClasspathElement>
</additionalClasspathElements>
<argLine>${surefire.argLine}</argLine>
<classesDirectory>${project.build.directory}/generated-classes/classes</classesDirectory>
<forkMode>once</forkMode>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-mockito-release-full</artifactId>
<version>1.5</version>
<classifier>full</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
--------------------

Johan Haleby

unread,
Jan 21, 2013, 2:27:43 AM1/21/13
to powe...@googlegroups.com
Hi,

I've never experienced this myself so I don't really know what's going on. It could be that you try to run the tests in parallel? Try to remove that line and see if it works. 

One thing that I notice is that your Maven configuration is incorrect. You should not depend on powermock-mockito-release-full but rather use what's stated in the getting started guide on the PowerMock web-page. I don't know if that'll solve it though but you can give it a try.

Regards,
/Johan


On Mon, Jan 21, 2013 at 12:49 AM, KARR, DAVID <dk0...@att.com> wrote:
powermock-mockito-release-full


KARR, DAVID

unread,
Jan 21, 2013, 10:01:34 AM1/21/13
to powe...@googlegroups.com

The Maven configuration was the key.  After I fixed that, the tests ran fine in Maven.

 

--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To post to this group, send email to powe...@googlegroups.com.
To unsubscribe from this group, send email to powermock+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/powermock?hl=en.

Johan Haleby

unread,
Jan 21, 2013, 10:17:25 AM1/21/13
to powe...@googlegroups.com
What did you change?

KARR, DAVID

unread,
Jan 21, 2013, 3:03:52 PM1/21/13
to powe...@googlegroups.com

As Johan refers to, the getting started page (http://code.google.com/p/powermock/wiki/Mockito_maven) says to include only the “powermock-module-junit4” and “powermock-api-mockito” artifacts, instead of the single “full” artifact that I had.

Johan Haleby

unread,
Jan 22, 2013, 2:36:23 AM1/22/13
to powe...@googlegroups.com
Alright, thanks for sharing.

Victor Dario Martinez

unread,
Jan 24, 2013, 2:58:37 PM1/24/13
to powe...@googlegroups.com
I had same problem: iIn eclipse works but when I run test from maven fails with a NullPointerExcepcion in mocked atributes.

pom.xml:

<dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>1.4.12</version>

            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito</artifactId>
            <version>1.4.12</version>

            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-easymock</artifactId>
            <version>1.4.12</version>
            <scope>test</scope>
        </dependency>

I need powermock-api-easymock in order to use: import org.powermock.api.easymock.annotation.Mock; that just is failing in maven.


Reply all
Reply to author
Forward
0 new messages