is 在Intellij中运行项目作为单元测试配置时,我正在遇到以下错误: /用户/francislainycampos/indueProjects/so-be-be-automation/src/test/java/java/com/francislainy/

问题描述 投票:0回答:0
/Users/francislainycampos/IdeaProjects/so-be-automation/src/test/java/com/francislainy/sobeautomation/steps/MySteps.java:14:30 java: variable restClient not initialized in the default constructor

,但是,当我从终端运行时,相同的测试正常。 我的设置 restclient.java

mvn test

cucumberspringConfiguration.java

@Slf4j @Component @AllArgsConstructor public class RestClient { public RequestSpecification getRequestSpecification() { // Rest Assured config here } }

-testConfig.java

@CucumberContextConfiguration @SpringBootTest(classes = TestConfig.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class CucumberSpringConfiguration {}
mysteps.java

@ComponentScan(basePackages = {"com.francislainy.sobeautomation"}) @EnableAutoConfiguration public class TestConfig {}
POM.xml(相关依赖关系)

@RequiredArgsConstructor public class MySteps { private final RestClient restClient; private Response response; @Given("I send a GET request to the Bored API") public void iSendAGETRequestToTheBoredAPI() { response = restClient.getRequestSpecification().get("https://www.boredapi.com/api/activity"); } } 我尝试了什么
检查LOMBOK注释处理
:注释处理是Intellij(<dependencies> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-spring</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> )中的
Enabled
手动添加一个构造函数:如果我明确定义了Settings > Build, Execution, Deployment > Compiler > Annotation Processors中的构造函数,则该问题将解决:
改变了Lombok依赖关系的范围

MySteps.java

或将其作为未指定的默认范围。 trive的不同版本
    ,均为Lombok 1.18.30和最新的1.18.36.
  • 到目前为止,到目前为止,我发现的唯一workaround是删除compile并明确定义了我的变量的构造函数。 @RequiredArgsAnnotation
    问题
    
  • 为什么在运行
  • Intellij的单元测试配置中的测试时无法初始化public class MySteps { private final RestClient restClient; private Response response; public MySteps(RestClient restClient) { this.restClient = restClient; } } ,但是可以与
    @RequiredArgsConstructor
    一起使用
  • restClient
  • ?是否有一种方法可以确保在两种情况下都能确保Lombok生成的构造函数正常工作?
  • https://github.com/francislainy/so-be-automation- 谢谢你

它是运行时错误,而不是源代码错误。

	
java spring-boot maven lombok intellij-lombok-plugin
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.