当前位置: 首页 > 知识库问答 >
问题:

在Junit5环境下运行Junit4测试,所有测试用例都失败

松旻
2023-03-14

我试图在JUnit5测试环境中使用JUnit4。事实上,我已经升级了我的pom来使用更高版本的MOckito和POwerMock。到目前为止,所有测试都基于JUnit4。我将平台和vintage依赖项添加到我的pom.xml中。

更早的pom。xml依赖关系

    <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-core</artifactId>
                <version>1.9.5</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.powermock</groupId>
                <artifactId>powermock-module-junit4</artifactId>
                <version>1.6.1</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.powermock</groupId>
                <artifactId>powermock-api-mockito</artifactId>
                <version>1.6.1</version>
                <scope>test</scope>
            </dependency>

    Latest pom.xml dependencies



        <dependency>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
                <version>5.3.2</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-core</artifactId>
                <version>2.23.4</version>
                <scope>test</scope>
            </dependency>
<dependency>
                <groupId>org.powermock</groupId>
                <artifactId>powermock-module-junit4</artifactId>
                <version>2.0.0</version>
                <scope>test</scope>
            </dependency>
            <dependency>


<groupId>org.powermock</groupId>
                    <artifactId>powermock-api-mockito2</artifactId>
                    <version>1.7.4</version>
                    <scope>test</scope>
                </dependency>


    i m getting below errors

     Errors: 
    [ERROR]   IntegratorAccessUpdateTest.testBeanProperties:13 » NullPointer
    [ERROR]   ActionHistoryTest.testBeanProperties » StackOverflow
    [ERROR]   ApplicationPreferenceManagerTest.testGetBoolean » NoClassDefFound org/powermoc...
    [ERROR]   ApplicationPreferenceManagerTest.testGetString » NoClassDefFound org/powermock...
    [ERROR]   CommonValidatorsDispatcherTest.setUp:25 » IllegalState Could not initialize pl...
    [ERROR]   CommonValidatorsDispatcherTest.setUp:25 » IllegalState Could not initialize pl...


  How can i remove these errors, I am not sure that changing each and every class   is feasible.is there is any compatibility issue with the versions? why is it   showing stackoverflow error?

共有1个答案

拓拔骁
2023-03-14

君尼特提供了有关如何从君尼特4升级到君尼特5的指导。https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4

 类似资料:
  • 有一种方法可以运行junit测试,只需在“mvn clean install”命令中添加参数?没有使用@Profile注释测试。

  • 我有一个工作环境,包括我不管理的bom和JUnit5测试,除非我从如果我从它们不会被maven surefire插件拾取。我阅读了许多部分,并在一个较小的项目中进行了测试,它的工作和拾取,我不知道该在这篇文章中包含什么,因此您有足够的信息来查看问题所在。此外,如果有人能解释我阅读的导入的幕后内容,JUnit 4和5都需要使用surefire即 与版本 我很感激。 注意到 < li >我的测试都在s

  • 对于测试证据,我想将我写到特定目录中的所有测试工件(例如服务器调用和响应)存档。我得到了压缩目录的方法,但我没有找到合适的地方来执行它。 测试生命周期回调似乎不是正确的位置,因为@AfterAll在每个测试类之后被调用,但是存档应该在所有测试类中的所有测试终止后生成。 在阅读了诸如如何在模块中执行之前和之后分别编码一次的帖子之后?似乎没有希望在jUnit中执行调用。 我找到了一个扩展TestLau

  • 问题内容: 在JUnit4中可以吗? 在JUnit3中,我将执行以下操作: 问题答案: takari-cpsuite(最初由Johannes Link 开发)提供了一个适合您需求的classpath- suite。它允许通过正则表达式对Classpath中的类进行过滤,例如:

  • 问题内容: 我有一个包含多个模块的项目。当所有测试通过时,Maven测试将全部运行。 当第一个模块中的测试失败时,maven将不会继续进行下一个项目。我在Surefire设置中将testFailureIgnore设置为true,但这无济于事。 我如何使Maven运行所有测试? 问题答案: 我刚刚找到了“ -fae”参数,该参数使Maven运行所有测试并且不会因失败而停止。

  • 我在测试用例中使用这三种方法,但有时脚本仍然无法等待元素的可见性,或者即使元素在运行时显示,它仍然失败。但当我重新运行它们时,它们会单独通过 例如,我有98个测试用例,第一次运行20个会失败,但是当我重新运行20个测试用例时,它们通过了