空手道启动功能
需要在所有测试用例执行之前执行运行状况检查"测试(功能).这就像执行一堆测试用例之前的初步测试.如果任何预检查失败,则需要一种解决方案来退出平台.
Need to execute a 'healthcheck' test(feature) before all the test-cases execute . This is like a preliminary test before executing the bunch of test-cases. Need a solutions to exit the platform if any of this pre check fails .
使用 karate.call
/从
, karate-config.js
执行运行状况检查功能karatecallSingle
Execute your health check feature from karate-config.js
using karate.call
/karatecallSingle
,
如果您的功能无法使用Java System.exit
强制终止测试.
if you feature fails to use java System.exit
to force kill your test.
karate-config.js的片段
snippet for karate-config.js
try{
var healthCheckInput = {};
var healthcheckCall = karate.callSingle("healthCheck.feature",healthCheckInput );
if (!<healcheckCondition>){
java.lang.System.exit(0);
}
}
catch(e){
java.lang.System.exit(0);
}
如果您的健康检查条件失败,这将强制退出您的处决.
if your health check condition failed this would force exit your execution.
不确定karate.abort()是否会从平台上退出,但是如果您打算实施,也请尝试此操作.
Not sure whether karate.abort() will give a soft exit from the platform, but if you are planning to implement try this as well.
注意:由于System.exit()强制中止了您的执行,因此您将无法正确获取任何报告,但可以引用控制台日志/空手道日志有待进一步调查.
Note: since System.exit() force kills your execution you will not get any reports properly, but you can refer console logs/karate logs for further investigation.
另一种方法
您可以在Junit @BeforeClass 内部使用空手道Java API 代码>运行您的健康状况检查功能.
You can use karate Java API inside Junit @BeforeClass
run your health status check feature.
@BeforeClass
public static void startUpCheck() {
Map<String, Object> args = new HashMap();
args.put("inputOne", "valueOne");
Map<String, Object> result = Runner.runFeature("classpath:stackoverflow/demo/healthCheck.feature", args, true);
// also assert the 'result' if you want OR keep some assertions/match in your feature
}