PowermockをMavenで実行できません。私は、jUnitテストを実行するためのPowerMockMockitoおよびPowerMockRunnerです。
テストは次のとおりです。
@RunWith(PowerMockRunner.class)
@PrepareForTest( { UserLocalServiceUtil.class, ExpandoBridge.class })
public class AlertNotificationsTest {
//...
テストを実行するための特別な設定はしていません。私のpomは次のdepsを参照しています:
- org.mockito | mockito-すべて| 1.8.0
- junit | junit | 4.6.0
- org.powermock.modules | powermock-module-junit4 | 1.3.1
- org.powermock.api | powermock-api-mockito | 1.3.1
mvnを実行するとmvn -Dtest=AlertNotificationsTest test
、実行するテストはないと表示されます。しかし、Eclipseから同じテストクラスを実行すると、すべてが正常に実行されます。
私は何か間違ったことをしていますか?
これが私のpom.xmlです(関連する部分)
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.9</version>
<classifier>jdk15</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock.modules</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock.api</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>
これがMavenからの出力です
mvn -Dtest=AlertNotificationsTestテスト
...
[INFO] Surefire report directory: C:\Devel\Java\EP_PORTAL\information-provider\target\surefi
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.313 sec
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)
[INFO] ------------------------------------------------------------------------
注:他のテストを実行することはできますが、このテストを実行することはできません。AlertNotificationsTest
クラスを拡張させると、クラスjunit.framework.TestCase
はMavenによってピックアップされますが、によって駆動されないようPowerMockRunner
です。
その出力は次のとおりです。
Running TestSuite
[ERROR]: No test suite found. Nothing to run
Tests run: 4, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 1.053 sec <<< FAILURE!
Results :
Failed tests:
testSingleEventNotification(pt.estradasportugal.traffic.services.events.AlertNotificationsTest)
testTwoEventNotification(pt.estradasportugal.traffic.services.events.AlertNotificationsTest)
Tests run: 4, Failures: 2, Errors: 0, Skipped: 0
繰り返しますが、これらのテストはEclipseで問題なく実行されます。
更新考えられる問題と回避策を見つけました。TestNGとJUnitを使ったテストがあります。PomからTestNGを削除し、すべてのテストをJUnitに移行すると、でPowerMockテストを実行できますmvn test
。したがって、Mavenとjunit/testngコンボに問題があるようです。
両方を実行できるようにしたいのですが、方法が見つからない場合は、自分の質問に答えます。ありがとうみんな&ギャルズ