java.lang.NoClassDefFoundError: org/junit/platform/launcher/TestExecutionListener
我正在尝试使用Intellij Idea创建一个测试类(JUNIT 5),但我遇到了Bellow错误.当我创建测试类时,它没有显示修复按钮,因此我很确定库在类路径中. Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/launcher/TestExecutionListener at java.base/java.lang.ClassLoader.defineClass1(Native Method) at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016) at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151) at java.base/jdk.int
12 2023-05-23
编程技术问答社区
未能解决junit平台启动器1.6.3 intellij的问题。
我正在尝试在Intellij中运行测试,该测试曾经在Spring Boot 2.2.x.x中工作.我最近升级为Spring Boot 2.3.9.当我尝试从运行配置运行测试时,它不会运行测试并引发错误: '未能解析junit平台启动器1.6.3 Intellij'. 但是,如果我在CLI中运行测试,则可以正常工作. 解决方案 事实证明,需要添加junit5-platform-launcher依赖项,以便在Intellij中运行Junit5测试. https://junit.org/junit5/docs/current/user-cuide/#running-tests-ide-intellij-idea 在pom.xml中明确添加此依赖关系,它将解决该问题. org.junit.platform junit-platform-launcher
6 2023-05-23
编程技术问答社区
@DirtiesContext不能与@Nested测试一起使用
在Google进行了数小时的研究之后,我仍然无法弄清楚如何使用@Nested类使用@DirtiesContext.假设以下集成测试类: @ExtendWith(SpringExtension.class) @SpringBootTest @AutoConfigureMockMvc(addFilters = false) public class StuffIntegrationTests { @Autowired private StuffRepository stuffRepository; @Autowired private WebApplicationContext context; private MockMvc mvc; // ... @BeforeEach private void setUp() { mvc = MockMvcBuilders
8 2023-05-23
编程技术问答社区
为什么使用Junit5和mocked beans的spring Boot 2.4.5会出现StackOverflowErrors?
上下文 将Gradle从5.5.1升级到7.0.2 测试 - 一切都起作用 弹簧从2.1.5升级到2.4.1 从Junit 4到Junit 5 迁移的测试注释 结果 Unitests工作 集成测试不要工作 问题 在应用程序上下文中重置模拟时,启动集成测试失败 @ResetMocksTestExecutionListneer.resetMocks 有问题的豆具有beanifyAuthenticationManager的名称,其代理interface org.springframework.security.authentication.AuthenticationManager 检测该豆是否mock跑入无限环路. 它的toString方法也是如此. 问题 我做错了什么吗? 这个问题应报告给春季吗? 其他信息 由定义为 的自定义注释触发的集成测试 @Documented @Inherited @Retention
2 2023-05-23
编程技术问答社区
如何在JUnit 5中使用字符串数组进行参数化
我想编写 junit 5 参数化测试,该测试将字符串阵列(String[])作为参数: @ParameterizedTest @MethodSource("stringArrayProvider") void parseFirstAndSecondInt(String[] args) { Arguments arguments = new Arguments(args); assertEquals(1, arguments.getFirst()); assertEquals(2, arguments.getSecond()); } 我不确定如何提供字符串数组的集合/流/迭代器.我已经尝试使用@MethodSource注释 未能成功尝试遵循方法 static Stream stringArrayProvider() { return Stream.of( new String[]{"1", "2"}
0 2023-05-19
编程技术问答社区
可以嵌套JUnit 5参数化测试吗?
我试图为接口FOO编写一个参数化测试,该测试声明了getFooEventInt(int,int)方法.我编写了一个适用于foo(fooimpl对象)的实例的参数化测试. public class FooTest { @ParameterizedTest @MethodSource("getFooEvenIntProvider") public void getFooEvenIntTest(int seed, int expectedResult) { Foo foo = new FooImpl(); Assertions.assertEquals(expectedResult, foo.getFooEvenInt(seed)); } private static Stream getFooEvenIntProvider() { return Stream.of( A
0 2023-05-19
编程技术问答社区
Gradle无法用useJUnitPlatform()运行JUnit测试。
我的项目是使用Java JDK 11的Gradle依赖Javafx项目.该项目是使用Gradle项目的默认结构进行的.因此,在SRC下,它具有"主要"和"测试",每个测试由" Java"和"资源"目录组成. 用于使用Jenkins设置CI管道,这是要求 gradlew Test 以与我的IDE(Intellij)到目前为止相同的方式运行所有测试.有趣的是,我无法在尝试几个小时后才能工作. dependencies { testImplementation 'org.junit.jupiter:junit-jupiter-api:5.1.0' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.1.0' } test { useJUnitPlatform() } application { mainClassName = 'FP.EDM.main/edm.Main' } 每当我运行gradlew test命令
6 2023-04-27
编程技术问答社区
在Gradle 6.1.1中无法解析junit-jupiter-params:5.6.2和junit-jupiter-engine:5.6.2
我有一个带有2个Android模块和一个纯Java模块的Android项目. 将Android构建工具更新为com.android.tools.build:4.0.0和Gradle包装器和Gradle-6.1.1-所有纯Java模块无法再解决Junit. 与Gradle文件同步时,我会收到以下错误: Failed to resolve: org.junit.jupiter:junit-jupiter-params:5.6.2 Failed to resolve: org.junit.jupiter:junit-jupiter-engine:5.6.2 如果我尝试直接运行测试,我将获得以下输出: Could not resolve all files for configuration ':domain:testCompileClasspath'. > Could not resolve org.junit.jupiter:junit-jupiter-par
14 2023-04-27
编程技术问答社区
org.spockframework.runtime.SpockEngine 在升级Groovy和Spock时,遇到了无法获得公共无参数构造函数的情况。
使用Gradle 7.1.1,Java 16,Groovy 3.0.8和Spock 2.0-Groovy-3.0 运行时我会遇到此错误./gradlewClean Test Caused by: java.util.ServiceConfigurationError: org.junit.platform.engine.TestEngine: org.spockframework.runtime.SpockEngine Unable to get public no-arg constructor at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:582) at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:673) at java.base/java.util.ServiceLoader$L
8 2023-04-27
编程技术问答社区
NoSuchMethodError-Intellij和lombok
我在Intellij中遇到了一个奇怪的问题.我正在使用Lombok(1.18.2),Intellij(2018.2.2)和junit 5在Gradle 4多模块项目中. 我花了几个小时才能复制这个. 运行所有带有覆盖范围的测试用例. 弹出窗口后将到来 如果我按确定并重新运行单元测试案例.它将开始使用 java.lang.nosuchmethoderror getters和setters. 在此之后删除Lombok并生成Getter和Setter也没有效果. 尝试解决此问题的所有问题(启用注释处理器,Lombok插件,清洁构建),但没有运气. 编辑1: root build.gradle: implementation 'org.projectlombok:lombok:1.18.2' testImplementation('org.junit.jupiter:junit-jupiter-api:5.3.1') testImplemen
2 2023-04-27
编程技术问答社区
运行gradle测试时,在嵌套的Kotlin类中找不到JUnit测试
当我在Kotlin中的嵌套类中指定测试时... import org.junit.jupiter.api.* class ParentTest { @Nested class NestedTest { @Test fun NotFoundTest() {} } @Test fun FoundTest() {} } ...使用Gradle运行测试时,JUNIT无法识别它.仅找到FoundTest并运行. 我正在使用Junit 5.1和Kotlin 1.2.30和Gradle 4.6. 解决方案 将嵌套类定义为 ninen Class 解决此问题. class ParentTest { @Nested inner class NestedTest { @Test fun InnerTestFound() {} }
2 2023-04-27
编程技术问答社区
ID为'junit-vintage'的TestEngine未能发现测试-JUnitException: 解析junit:junit的版本失败了: 4.13.2
我的gradle配置和junit有一个非常奇怪的问题,我尝试更新为5.7+,但是我得到以下例外: org/junit/jupiter/api/extension/ScriptEvaluationException java.lang.NoClassDefFoundError: org/junit/jupiter/api/extension/ScriptEvaluationException 顺便说一句,我的Gradle版本为6.8.3.另一方面,这是我在下面的当前配置中得到的例外,我尝试了很多版本和库的组合,小屋似乎没有一个可用: Caused by: org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-vintage' failed to discover tests at org.junit.platform.launcher.core.EngineDiscoveryOrch
36 2023-04-27
编程技术问答社区
未执行JUnit 5测试用例
我在Netbeans的一个新的清洁Maven项目中创建了此测试: import static org.junit.jupiter.api.Assertions.fail; import org.junit.jupiter.api.Test; public class JUnit501Test { @Test void firstTest() { fail("epicly"); } } 如果我运行测试,则日志显示 ------------------------------------------------------- T E S T S ------------------------------------------------------- Running JUnit501Test Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 se
8 2023-04-21
编程技术问答社区
什么';这是JUnit 5@Nested注释的目的
在Junit 5中,有一个新的注释: @Nested . 我了解注释的工作原理,我知道为什么我们使用嵌套类, 我只是不明白为什么我们需要进行嵌套测试类. 解决方案 @Nested注释允许您拥有一个本质上是测试类的内部类,可让您在同一父母下(使用相同的初始化)分组几个测试类. 其他解决方案 我只是不明白为什么我们需要在我们的 测试. @Nested组织大型测试课确实很有意义. 典型用例 通常,开发人员团队按类定义测试以进行测试. 这是一种共同的良好做法,但它也可能使您的考试课非常大并计算数百行.您确实可以使用多种方法测试类测试,每个方案的多个方案以及单元测试方法中所需的一些初始化步骤来测试方案. 所有这些自然都会增加考试课程的规模. 高于阈值(也许是500行或大约),问自己是否需要重构是合法的. 一个很大的班级(无论是否测试课程),即使有井井有条,也很难阅读,维护多个类别的多个类,分组具有高凝聚力/关系的事物. 在单元测试情况下,情况
2 2023-04-20
编程技术问答社区
无法连接到Testcontainer Neo4J实例?
这是我的测试课: @Testcontainers @ReactiveDataNeo4jTest internal class RepositoryIT { @Container private val container = KNeo4jContainer.instance @Test fun `should answer with One`() { val boltUrl = container.getBoltUrl() GraphDatabase.driver( boltUrl, AuthTokens.basic("neo4j", "123456")) .use { driver -> driver.session().use { session ->
2 2023-04-20
编程技术问答社区
如何使用JUnit 5(在Kotlin中)设置Spring数据Neo4j集成测试?
网络周围的大多数示例与Neo4J进行春季集成测试仍在Junit 4上,并使用Neo4Jrule. 我们如何为neo4j + spring + junit 5创建设置5? 解决方案 如果您要在嵌入式上进行测试,请使用简单的弹簧配置使用测试线束. 这里有一些示例: httpps ://github.com/michael-simons/neo4j-sdn-ogm-tips/tree/master/examples/using-the-test-harness https://github.com/Michael-Simons/neo4j-sdn-ogm-tips/tree/tree/master/示例/ludes-testContainers https://github.com/neo4j/neo4j-java-driver-spring-spring-boot-starter/tree/master/master/examples/testing-with
2 2023-04-20
编程技术问答社区
@InjectMock是否只在一个类的全局变量中注入模拟?
我尝试进行以下测试: import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) public class SomeClassTest { // needs to be mocked and injected @Mock private SomeDao someDao; @InjectMocks private SomeClass someClass = n
0 2023-04-14
编程技术问答社区
Cucumber 没有发现JUnit5的功能
我正在尝试在项目中设置黄瓜.我正在遵循以前项目中相同的配置,但是我在运行测试方面仍然存在问题.现在,我开始怀疑问题可能是该项目使用Junit 5而不是4.我也将Junit4添加到构建选项中,以便能够使用Junit4执行@runwith注释,但是我仍然得到相同的操作错误(在ClassPath中找不到功能). 跑步者类如下: import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; import io.cucumber.junit.CucumberOptions.SnippetType; import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions(features = "classpath:resources", plugin = {"pretty", "html:target/reports/c
2 2023-04-13
编程技术问答社区
在Spring Boot 2.2和JUnit 5下,Maven测试不能运行Cucumber场景
我正在春季靴子2.2.6尝试Junit 5和Cucumber,并且在我的应用程序中需要BDD方案和单元测试.我创建了一个虚拟控制器对应的功能文件,这是可以的. 当我运行mvn clean test时, 黄瓜测试未调用.仅调用JUNIT测试.但是,当单击CucumberTest.java> CucumberTest.java的按钮时,我可以从Intellij GUI运行黄瓜方案. 这是我的课程: DummyApplicationTests.java: package com.a.dummy; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.contex
38 2023-04-13
编程技术问答社区