您有 Spoon 插件,但正在运行gradle :app:connectedCheck
。首先,进行这些更改,然后运行gradle spoon
注释掉 androidTest.setRoot
除主包之外的任何其他 build.gradle
将这些添加到build.gradle
主包的内容:
标签下android
sourceSets { //this one may not be needed. But wont hurt.
androidTest.setRoot('src/androidTest')
}
Modify spoon
tag:
spoon {
debug = true
testSizes = ['small', 'medium', 'large'] <<--- Change this to run specific test sizes
if (project.hasProperty('spoonClassName')){
className = project.spoonClassName
}
}
To run
所有测试:
梯度勺
具体测试类
gradle Spoon -PspoonClassName = [THE.PACKAGE.NAME]
Edit
阅读您的编辑“Edit2”后,我发现这只会指定要运行的某个类,而不是特定的包。不幸的是,我还没有找到解决方案,只有一个解决方法。我构建了一个 bash 脚本,并在其中添加了要测试的类,如下所示:
Step 1:在 Android 项目的根目录下创建一个文件:runAllTests.sh
Step 2: Edit .sh
看起来像这样:
#!/bin/sh
date +%b-%dT%H.%M > timestamp.out
sites="$HOME"/path/to/project/root
timestamp="$(cat "$sites"/timestamp.out)"
result_folder="$sites"/results
destdir="$result_folder/Results-$timestamp"
mkdir -p "$destdir"
echo "Directory created: ${destdir##*/}"
<---------- Here you start running the test --------------->
echo "Starting Master Setup"
gradle spoon -PspoonClassName=com.espresso.test.MasterSetup
cp -r "$sites"/app/build/spoon "$destdir"/MasterSetup
echo "Results saved to MasterSetup"
echo "Starting WorkoutSchedule"
gradle spoon -PspoonClassName=com.espresso.test.CupcakeSchedule
cp -f "$sites"/app/build/spoon "$destdir"/WorkoutSchedule
echo "Results saved to WorkoutSchedule"
echo "Starting Setting.test"
gradle spoon -PspoonClassName=com.espresso.test.Settings
cp -r "$sites"/app/build/spoon "$destdir"/Settings
echo "Results saved to Settings"
Step 3:给脚本权限
-
cd
到脚本
- type
chmod u+x runAllTest.sh
那么,这是做什么的:
首先,它创建一个 timestamp.out。我使用它是为了可以一遍又一遍地将结果保存到文件中,而不会覆盖以前的结果。您不需要这部分。
接下来,它会在项目的根目录中创建一个结果文件夹(如果尚不存在)。
然后,它将在结果文件夹中创建一个名为 Results-SOME-DATE 的文件夹。
最后,每个测试都会运行,并将结果保存到项目的正常位置。 (在 build/spoon 内)测试完成后,它将把结果复制到结果文件夹中,并适当地命名每个测试结果,以便轻松查看运行的所有测试。
NOTE:该脚本是为 MAC 编写的。如果您使用的是 Windows 或其他任何设备,则此脚本可能需要修改。
此外:你会发现打开每个文件夹来获取文件很不方便index.html
打开。所以我写了这个脚本来添加到你的bash_profile
:
function open-results () {
# the browser to open up `index.html' in.
browser='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
# let the user know what directory we're looking in
printf "looking in %s" "$(pwd)"
echo ...
for paths in $(find ./ -name 'debug' -type d); do
for files in $(find "$paths" -name 'index.html'); do
open -a "$browser" "$files"
done
done
echo done
}
现在,cd 到Results-SOME-DATE
,然后输入open-results
. Again,这是为 bash 编写的。您可能需要根据您的操作系统进行修改。但结构应该是一样的
我希望这有帮助。