简体   繁体   English

@RunWith(PowerMockRunner.class)与tycho surefire不兼容

[英]@RunWith(PowerMockRunner.class) do not work with tycho surefire

I currently want to run JUnits using PowerMockito on CI server using Tycho-Surefire (OSGi project). 我目前想在使用Tycho-Surefire(OSGi项目)的CI服务器上使用PowerMockito运行JUnits。 I prepared simple class: 我准备了简单的课程:

 @RunWith(PowerMockRunner.class)
 public class SampleFirstTest {


@Test
public void addingTest() {
    assertEquals(10, 10);
}

This test class perfectly and successfully runs when has no @RunWith annotation, but when I add this annotation I get: 没有@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.

(Btw. This class should work with annotation because when I use eclipse launcher it works in both ways) (顺便说一句,该类应与注释一起使用,因为当我使用Eclipse启动器时,它可以同时以两种方式工作)

And In test report I get: 在测试报告中,我得到:

 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)

I read that to fix that problem I should use JUnit version 4.1.1 and PowerMock 1.5.6 but It still fails... This is important part of parent pom: 我读到要解决该问题,我应该使用JUnit版本4.1.1和PowerMock 1.5.6,但仍然失败...这是父pom的重要部分:

 <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>

To test I use: 要测试我使用:

 mvn clean package target-platform-configuration:target-platform tycho-surefire:test -X

Update: 更新:

Notice that for OSGi the last version is 1.5.6 - https://code.google.com/p/powermock-osgi/ 请注意,对于OSGi,最新版本是1.5.6- https://code.google.com/p/powermock-osgi/

So in my case I want to stay in 1.5.6 version. 因此,就我而言,我想保留1.5.6版本。 And JUnit 4.11 but with some reason it still do not work. 和JUnit 4.11但由于某种原因它仍然无法正常工作。

Thanks in advance for replays ! 预先感谢重播! :) :)

Ok now I know what was the reason. 好吧,现在我知道是什么原因。 I had a plugin which has dependency to org.junit, I just had to exclude version 4.12 and everything is ok. 我有一个依赖于org.junit的插件,我只需要排除版本4.12,一切都很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 问题在于@RunWith(PowerMockRunner.class) - the problem is with @RunWith(PowerMockRunner.class) RunWith(PowerMockRunner.class)不适用于包注释 - RunWith(PowerMockRunner.class) does not work with package annotation 没有@RunWith的模拟静态(PowerMockRunner.class) - mock static without @RunWith(PowerMockRunner.class) 使用 @RunWith(PowerMockRunner.class) 时出现 NoClassDefFoundError - NoClassDefFoundError when using @RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)vs @RunWith(MockitoJUnitRunner.class) - @RunWith(PowerMockRunner.class) vs @RunWith(MockitoJUnitRunner.class) @RunWith(PowerMockRunner.class)说@RunWith不适用于方法 - @RunWith(PowerMockRunner.class) says @RunWith not applicable to method PowerMock从@RunWith(PowerMockRunner.class)批注引发异常 - PowerMock Throwing an Exception from @RunWith(PowerMockRunner.class) Annotation 带有@RunWith(PowerMockRunner.class)批注的测试类在扩展另一个类时两次运行测试用例 - Test Class with @RunWith(PowerMockRunner.class) annotation runs test cases twice when extending another class 使用@RunWith(PowerMockRunner.class)进行Junit测试失败 - “没有找到匹配的测试......” - Junit test with @RunWith(PowerMockRunner.class) fails - “No tests found matching..” @RunWith(PowerMockRunner.class)是否在每次测试之前为使用@Mock注释的成员注入新的模拟? - Does @RunWith(PowerMockRunner.class) inject new mocks for members annotated with @Mock prior to each test?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM