Cucumber + Spring Boot的 "路径必须存在"。

问题描述 投票:1回答:1

我做了一个 Spring Boot 2 应用程序,用一个端点来执行 Cucumber test 5.7.0版本

@PostMapping("/integration")
public Object runCucumber(@RequestBody List<String> request) {
    try {

        String pathDirectory = "src/main/resources/" + request.get(0);


        String response = String.valueOf(Main.run(new String[]{"--glue", //Cucumber type (--glue)
                        "pmc/aop/integration", // the package which contains the glue classes
                        pathDirectory} //Step package
                , Thread.currentThread().getContextClassLoader()));

        return ResponseEntity.ok(request);

    } catch (HttpClientErrorException ex) {

        log.error(ex.getLocalizedMessage());

        return ResponseEntity.status(ex.getStatusCode()).body(ex.getStatusText());

    } catch (IllegalArgumentException ex) {

        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ex.getLocalizedMessage());

    }
}

请求中使用了

[
"features/local/notify.feature"
]

enter image description here

如你所见,我想执行的是 notify.feature 里面 local 文件夹,在 features 文件夹,在 resources 夹子

这是配置

@SpringBootTest
@AutoConfigureMockMvc
@CucumberContextConfiguration
@CucumberOptions(features="src/main/resources")
public class CucumberConfiguration {
}

一切都很顺利,在本地,但在我的服务器上,我得到的是

path must exist: /app/src/main/resources/features/local/heal.feature

错在哪里?

java spring-boot cucumber cucumber-java
1个回答
1
投票

当你的应用程序被部署到 src/main/resources/ 目录不存在。你可以通过检查你创建的jar或war文件的内容来验证这一点。

相反,尝试在类路径上定位该功能。例如 classpath:com/example/app/my.feature.

© www.soinside.com 2019 - 2024. All rights reserved.