Non riesco a eseguire Powermock tramite Maven. Sono il PowerMock Mockito e PowerMockRunner per aver guidato un test di jUnit.Esecuzione di Junit e PowerMock con Mockito tramite PowerMockRunner di Maven
Ecco il test:
@RunWith(PowerMockRunner.class)
@PrepareForTest({ UserLocalServiceUtil.class, ExpandoBridge.class })
public class AlertNotificationsTest {
//...
non ho configurato anyting speciale per l'esecuzione del test. Il mio pom fa riferimento ai seguenti punti:
- org.mockito | mockito-tutto | 1.8.0
- junit | unità | 4.6.0
- org.powermock.modules | powermock-module-junit4 | 1.3.1
- org.powermock.api | powermock-api-mockito | 1.3.1
quando corro mvn -Dtest=AlertNotificationsTest test
mvn dice che non c'è alcun test da eseguire. Ma se eseguo la stessa classe di test da Eclipse, tutto funziona correttamente.
Sto facendo qualcosa di sbagliato?
Ecco la mia pom.xml di seguito (le parti pertinenti)
<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>
Ecco l'output di Maven
mvn -Dtest = AlertNotificationsTest prova
...
[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] ------------------------------------------------------------------------
Nota: Posso eseguire altri test, non riesco a eseguire questo test. Se faccio sì che la classe AlertNotificationsTest
estenda junit.framework.TestCase
, la classe viene rilevata da Maven, ma sembra che non venga guidata da PowerMockRunner
.
ecco l'output di che:
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
Ancora una volta, questi test girare bene con Eclipse.
Aggiornamento ho trovato un possibile problema & soluzione. Ho dei test con TestNG e JUnit. Se rimuovo TestNG dal mio pom e trasferisco tutti i miei test su JUnit, sono in grado di eseguire il test PowerMock con mvn test
. Quindi sembra che ci sia un problema con maven e la combinazione junit/testng.
Mi piacerebbe essere in grado di eseguire entrambi, ma se non trovo un modo, andrò a rispondere alla mia stessa domanda. Grazie ragazzi & ragazze
è la prova (che non si estende 'junit.framework.TestCase') innescato quando esegui semplicemente 'mvn test'? –
No, non è attivato. –
Quindi non aspettatevi nemmeno che sia quando si usa '-Dtest'. Hai un altro problema (e sembra che tu abbia trovato la fonte). –