/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
mvn test
@Slf4j
@Component
@AllArgsConstructor
public class RestClient {
public RequestSpecification getRequestSpecification() {
// Rest Assured config here
}
}
@CucumberContextConfiguration
@SpringBootTest(classes = TestConfig.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class CucumberSpringConfiguration {}
@ComponentScan(basePackages = {"com.francislainy.sobeautomation"})
@EnableAutoConfiguration
public class TestConfig {}
@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");
}
}
我尝试了什么
<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>
)中的。
Settings > Build, Execution, Deployment > Compiler > Annotation Processors
中的构造函数,则该问题将解决:MySteps.java
compile
并明确定义了我的变量的构造函数。
@RequiredArgsAnnotation
问题
public class MySteps {
private final RestClient restClient;
private Response response;
public MySteps(RestClient restClient) {
this.restClient = restClient;
}
}
,但是可以与@RequiredArgsConstructor
一起使用restClient
它是运行时错误,而不是源代码错误。