0

そのため、Mavenタスクの引数として提供されているテストファイルを使用して、一連の(Maven)テストを実行する必要があります。

このようなもの:

mvn clean test -Dtest=<filename>

また、テストファイルは通常、さまざまなディレクトリに編成されています。したがって、上記の「コマンド」を実行し、指定されたディレクトリ内のすべてのファイルの名前をに自動的にフィードするスクリプトを作成しようとしています-Dtest

そこで、「run_test」というシェルスクリプトから始めました。

#!/bin/sh
if test $# -lt 2; then
    echo "$0: insufficient arguments on the command line." >&1
    echo "usage: $0 run_test dirctory" >&1
    exit 1
fi
for file in allFiles <<<<<<< what should I put here? Can I somehow iterate thru the list of all files' name in the given directory put the file name here?
     do mvn clean test -Dtest= $file  

exit $?

私が行き詰まった部分は、ファイル名のリストを取得する方法です。ありがとう、

4

2 に答える 2

1
#! /bin/sh
# Set IFS to newline to minimise problems with whitespace in file/directory 
# names. If we also need to deal with newlines, we will need to use
# find -print0 | xargs -0 instead of a for loop.
IFS="
"
if ! [[ -d "${1}" ]]; then
  echo "Please supply a directory name" > &2
  exit 1
else
  # We use find rather than glob expansion in case there are nested directories.
  # We sort the filenames so that we execute the tests in a predictable order.
  for pathname in $(find "${1}" -type f | LC_ALL=C sort) do
    mvn clean test -Dtest="${pathname}" || break
  done
fi
# exit $? would be superfluous (it is the default)
于 2012-05-11T19:50:44.263 に答える
1

ディレクトリ名が含まれていると仮定すると$1(ユーザー入力の検証は別の問題です)、

for file in $1/*
do
    [[ -f $file ]] && mvn clean test -Dtest=$file
done

すべてのファイルでコマンドを実行します。サブディレクトリに再帰する場合は、findコマンドを使用する必要があります

for file in $(find $1 -type f)
do
    etc...
done
于 2012-05-11T19:52:38.723 に答える