Java @RunWith(PowerMockRunner.class)不与tycho surefire一起工作
我目前想在使用Tycho Surefire(OSGi项目)的CI服务器上使用PowerMockito运行JUnits。我准备了简单的课程:Java @RunWith(PowerMockRunner.class)不与tycho surefire一起工作,java,eclipse,maven,junit,tycho-surefire-plugin,Java,Eclipse,Maven,Junit,Tycho Surefire Plugin,我目前想在使用Tycho Surefire(OSGi项目)的CI服务器上使用PowerMockito运行JUnits。我准备了简单的课程: @RunWith(PowerMockRunner.class) public class SampleFirstTest { @Test public void addingTest() { assertEquals(10, 10); } 当没有@RunWith注释时,此测试类完美且成功地运行,但当我添加此注释时,我得到: org.apa
@RunWith(PowerMockRunner.class)
public class SampleFirstTest {
@Test
public void addingTest() {
assertEquals(10, 10);
}
当没有@RunWith注释时,此测试类完美且成功地运行,但当我添加此注释时,我得到:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.eclipse.tycho:tycho-surefire-plugin:0.24.0:test (default-cli) on project jenkins.junit: There are test failures.
(顺便说一句,这个类应该与注释一起工作,因为当我使用eclipse启动器时,它可以以两种方式工作)
在测试报告中,我得到:
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.827 sec <<< FAILURE! - in sample.SampleFirstTest
initializationError(sample.SampleFirstTest) Time elapsed: 0 sec <<< ERROR!
org.powermock.reflect.exceptions.FieldNotFoundException: Field 'fTestClass' was not found in class org.junit.internal.runners.MethodValidator.
at org.powermock.reflect.internal.WhiteboxImpl.getInternalState(WhiteboxImpl.java:581)
更新:
请注意,OSGi的最新版本是1.5.6-
因此,在我的情况下,我想留在1.5.6版本。和JUnit4.11,但出于某种原因,它仍然不起作用
提前感谢您的重播!:) 好了,现在我知道原因了。我有一个插件,它依赖于org.junit,我只需要排除版本4.12,一切正常。可能的副本必须至少使用PowerMock 1.6.1。请看:我读了这篇文章,有一个答案:如果您不能升级PowerMock,那么您可以使用JUnit4.11。testCompile'junit:junit:4.11','org.powermock:powermock core:1.5.6','org.powermock:powermock-module-junit4:1.5.6','org.powermock:powermock-api-mockito:1.5.6',顺便说一句,这就是我所做的。对于OSGi,1.5.6是最新版本:junit4.11还有问题吗?是的,JUnit 4.1.1和PowerMock 1.5.6也存在同样的问题。。。
<properties>
<tycho-version>0.24.0</tycho-version>
<release-version>1.0/20</release-version>
<show-eclipse-log>true</show-eclipse-log>
<junit-version>4.1.1</junit-version>
<powermock.version>1.5.6</powermock.version>
</properties>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<argLine>-XX:-UseSplitVerifier</argLine>
<osgiDataDirectory>${basedir}/runtime-workspace-junit/</osgiDataDirectory>
<deleteOsgiDataDirectory>false</deleteOsgiDataDirectory>
<useUIHarness>false</useUIHarness>
<useUIThread>false</useUIThread>
<dependencyManagement>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
</dependencyManagement>
</configuration>
</plugin>
<dependencies>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-easymock</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-classloading-base</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>javassist</artifactId>
<version>3.8.0.GA</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>15.0</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr</artifactId>
<version>3.2</version>
</dependency>
</dependencies>
mvn clean package target-platform-configuration:target-platform tycho-surefire:test -X