简体   繁体   English

从bash脚本一个接一个地执行Java Cucumber功能文件,并在第一个功能完成后继续执行功能文件

[英]Executing Java Cucumber feature files one by one from bash script and continue execution of feature files after first one has completed

I have a need to run a bunch of Java cucumber feature files, one by one, by using a bash script on MacOS High Sierra. 我需要通过在MacOS High Sierra上使用bash脚本逐一运行一堆Java Cucumber功能文件。 The problem I have is, as soon as the first feature file is done executing (either success or failure), the Cucumber framework does its reporting on that feature file and my script does not execute the remaining feature files. 我遇到的问题是,一旦第一个功能文件执行完毕(成功或失败),Cucumber框架便会对该功能文件进行报告,而我的脚本不会执行其余的功能文件。 It "returns" to the command line. 它“返回”到命令行。

Here is part of the script that runs the cucumber files one by one: 这是脚本的一部分,该脚本逐一运行黄瓜文件:

function run_cucumber_features {
  for file in $(find ./src/test  -name '*Steps.feature' -print0 | xargs -0);
    do gradle cucumberTest -Dcucumber.options="$file" DmutationTesting="false" -DmutationParameter="$parameter";
  done
}

For example, let's say I execute my script: 例如,假设我执行我的脚本:

./mutation_testing.sh 

The script then invokes Cucumber and the first feature the script finds execute, and then it 'exits' with the status code for that specific feature: 然后,该脚本调用Cucumber,并找到该脚本执行的第一个功能,然后使用该特定功能的状态代码“退出”:

BUILD Success in 18s
7 actionable tasks: 5 executed, 5 succeeded

However, it then does not proceed to execute the next feature file, it returns to the command line: 但是,它随后不会继续执行下一个功能文件,而是返回到命令行:

username$ 

My question is whether there is a way for my script to not stop executing once Cucumber has done its reporting after every feature file that has been executed? 我的问题是,在每个功能文件执行完毕后,一旦Cucumber完成了报告,是否有一种方法可以使我的脚本不停止执行?

The error seems to be related to the steps inside your build.gradle file or the way you call the function in the Bash script. 该错误似乎与build.gradle文件中的步骤或Bash脚本中调用函数的方式有关。

A small test set-up. 一个小的测试设置。 Assume the following structure#!/bin/bash 假定以下结构#!/ bin / bash

run-gradle-loop.sh                    # executable script
gradle                                # executable script, as simple replacement
src/test/subdir/file2_Steps.feature   # a dummy file
src/test/file1_Steps.feature          # a dummy file

run-gradle-loop.sh run-gradle-loop.sh

#!/bin/bash

function run_cucumber_features {
  for file in $(find ./src/test  -name '*Steps.feature' -print0 | xargs -0);
  do
    gradle cucumberTest -Dcucumber.options="$file" DmutationTesting="false" -DmutationParameter="$parameter";
    echo "return code = $?"
  done
}

# to run the gradle script in the current directory
export PATH=$(pwd):${PATH}

run_cucumber_features

gradle gradle这个

#!/bin/bash

echo
echo "running gradle dummy"
echo "passed parameters : $@"

# exit with an error code
exit 1

file1_Steps.feature and file2_Steps.feature are two empty files, only to fulfill the loop criteria. file1_Steps.featurefile2_Steps.feature是两个空文件,仅满足循环条件。

The aim of the test is to check the behavior where gradle exit with an error code. 测试的目的是检查带有错误代码的gradle退出的行为。

run the main Bash script 运行主要的Bash脚本

./run-gradle-loop.sh

output 产量

running gradle dummy
passed parameters : cucumberTest -Dcucumber.options=./src/test/subdir/file2_Steps.feature DmutationTesting=false -DmutationParameter=
return code = 1

running gradle dummy
passed parameters : cucumberTest -Dcucumber.options=./src/test/file1_Steps.feature DmutationTesting=false -DmutationParameter=
return code = 1

This shows that even gradle would return with an error code the loop processes all .*Steps.feature files. 这表明即使gradle也会返回错误代码,循环.*Steps.feature处理所有.*Steps.feature文件。

edit One way it might stop after the first error could be that in the run-gradle-loop.sh script there is a set -e statement. 编辑在第一个错误之后可能会停止的一种方式可能是,在run-gradle-loop.sh脚本中有一个set -e语句。

man bash

-e Exit immediately if a pipeline (which may consist of a single simple command), a list, or a compound command -e如果管道(可能由一个简单命令组成),列表或复合命令立即退出

Which means. 意思是。 When the script gradle fails with an error the control is not returned to run-gradle-loop.sh . 当脚本gradle因错误而失败时,控件不会返回到run-gradle-loop.sh The output with above set-up would be 具有以上设置的输出将是

$ ./run-gradle-loop.sh

running gradle dummy
passed parameters : cucumberTest -Dcucumber.options=./src/test/subdir/file2_Steps.feature DmutationTesting=false -DmutationParameter=

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

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