Tôi không thể chạy Powermock thông qua maven. Tôi là PowerMock Mockito và PowerMockRunner để lái thử một bài kiểm tra jUnit.Chạy Junit & PowerMock với Mockito thông qua PowerMockRunner từ maven
Dưới đây là các bài kiểm tra:
@RunWith(PowerMockRunner.class)
@PrepareForTest({ UserLocalServiceUtil.class, ExpandoBridge.class })
public class AlertNotificationsTest {
//...
Tôi đã không được cấu hình anyting đặc biệt để chạy thử nghiệm. Tài liệu tham khảo pom của tôi bao gồm các thông tin sau:
- org.mockito | mockito-all | 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
khi tôi chạy mvn -Dtest=AlertNotificationsTest test
mvn cho biết không có thử nghiệm nào để chạy. Nhưng nếu tôi chạy cùng một lớp thử nghiệm từ nhật thực, mọi thứ đều chạy ok.
Tôi có làm gì sai không?
Dưới đây là pom.xml của tôi dưới đây (các bộ phận liên quan)
<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>
Dưới đây là kết quả từ maven
mvn -Dtest = AlertNotificationsTest kiểm tra
...
[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] ------------------------------------------------------------------------
Lưu ý: Tôi có thể chạy các thử nghiệm khác, tôi không thể chạy thử nghiệm này. Nếu tôi thực hiện lớp học AlertNotificationsTest
mở rộng junit.framework.TestCase
lớp học được chọn bởi maven, nhưng có vẻ như nó không được điều khiển bởi PowerMockRunner
.
Dưới đây là đầu ra của rằng:
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
Một lần nữa, những thử nghiệm này chỉ chạy tốt với Eclipse.
Cập nhật Tôi tìm thấy một vấn đề có thể & workaround. Tôi có các bài kiểm tra với TestNG và JUnit. Nếu tôi loại bỏ TestNG khỏi pom của tôi và di chuyển tất cả các thử nghiệm của tôi sang JUnit, tôi có thể chạy thử nghiệm PowerMock của mình với mvn test
. Vì vậy, có vẻ như có vấn đề với maven và combo junit/testng.
Tôi muốn có thể chạy cả hai, nhưng nếu tôi không tìm được cách tôi sẽ đi và trả lời câu hỏi của riêng tôi. Thanks guys & gals
là bài kiểm tra (không mở rộng 'junit.framework.TestCase') được kích hoạt khi bạn chạy 'mvn test'? –
Không, nó không được kích hoạt. –
Sau đó, thậm chí không mong đợi nó được khi sử dụng '-Dtest'. Bạn có một vấn đề khác (và có vẻ như bạn đã tìm thấy nguồn). –