黄瓜:如何在黄瓜JVM中的每个场景之后获取已执行步骤的列表

时间:2015-10-08 10:19:37

标签: java cucumber

我在我的一个项目中使用黄瓜JVM。我希望一旦失败就得到一个场景的所有步骤列表。有什么方法可以做到这一点吗?

1 个答案:

答案 0 :(得分:0)

一位同事给了我一个bash脚本来寻找步骤

#!/bin/bash

echo "Preparing list of step definitions in directory: $1"
echo "Steps marked with * are unused!"
steps=/tmp/step-definitions.txt
ack-grep "^\s*@(Given|When|Then|And).+" --java -h $1 | sed -r -e 's/^ +@(Given|When|Then|And) *\([^"]*|\) *$//g' -e 's/^"\^?|"$//g' | sort > $steps

used=used-steps.txt
unused=unused-steps.txt
> $used
> $unused

echo "Determine step definition usage:"
while read regex; do
  lc=$(find $1 -iname "*.feature" | xargs egrep "$regex" | wc -l)
  printf -v lcf "%03d" $lc
  if [[ $lc == 0 ]]; then
    echo "* $regex"
    echo $regex >> $unused
  else
    echo "  $regex"
    echo "$lcf uses: $regex" >> $used
  fi
done < $steps