繁体   English   中英

在常规应用程序上下文而不是测试上下文中从 API 运行测试

[英]Running a test from an API in regular application context instead of test context

我想创建一个黄瓜测试应用程序,它将从 API 输入(如 POST-@RequestBody)中获取一个功能文件,然后运行该文件的测试。 根据我的研究,我没有看到任何可能的方法来代替在@SpringBootTest 中设置所有内容,在资源中包含测试文件,然后运行mvn test 这不是运行测试的好方法,因为您必须进入应用程序添加或修改场景文件,然后运行测试。 从带有文件输入的 API 运行测试对于其他人来说会更容易使用,因为黄瓜的目标是在没有大量编码的情况下使其人性化。

我发现这个解决方案有效。 虽然,它没有为您提供外壳。

  • 使用测试单元创建一个普通的应用程序。
  • 确保 maven/gradle 已安装并添加到 PATH
  • 在常规应用程序中,创建使用以下代码的方法:

 // windows: "cmd","/c" // unix: "/bin/sh","-c" ProcessBuilder builder = new ProcessBuilder("cmd","/c","mvn","test"); builder.redirectErrorStream(true); Process p = builder.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); // code to process test result from reader // I only need to send this back to as API response. So there were no other impl

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM