gpt4 book ai didi

gradle - 使用 Espresso 运行特定测试

转载 作者:行者123 更新时间:2023-12-01 09:58:20 26 4
gpt4 key购买 nike

我目前正在通过命令运行我的测试

gradle app:connectedCheck

这很好用,但随着我的测试不断增加,我不想在尝试创建测试时经历所有测试。有谁知道如何只运行我的一个测试?提前致谢。

最佳答案

这是我在 MariusVolkhart 的帮助下完成的详细解决方案:

将此添加到您的 build.gradle:

spoon {
if (project.hasProperty('spoonClassName')){
className = project.spoonClassName
}
}

现在,您可以使用如下命令执行特定类:

gradle spoon -PspoonClassName=< com.your.pakage.ClassName>


就是这样!

但是,如果您想运行一系列特定测试,请在您的 Android 项目的根目录下创建一个文件:runAllTests.sh。此脚本将包含要运行的测试命令。

编辑你的 .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.WorkoutSchedule
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"

然后,给脚本权限 1. cd 到脚本 2. 输入chmod u+x runAllTest.sh

您已准备就绪。现在只需cd 到您的根目录,然后键入 执行您的测试。 runAllTest.sh

那么,这是做什么的:

  1. 首先,它创建一个 timestamp.out。我使用它是为了可以将我的结果一遍又一遍地保存到一个文件中,而不会覆盖以前的结果。你不需要这部分。
  2. 接下来,它会在项目的根目录中创建一个 result 文件夹(如果该文件夹尚不存在)。
  3. 然后,它将在结果文件夹中创建一个名为 Results-SOME-DATE 的文件夹。
  4. 最后,将运行每个测试,将结果保存到项目的正常位置。 (在 build/spoon 中)一旦测试完成,它会将结果复制到结果文件夹,并适本地命名每个测试结果,以便很容易看到所有测试运行。

注意:此脚本是为 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
}

现在,在终端中cdResults-SOME-DATE,然后输入open-results。同样,这是为终端编写的。您可能需要根据您的操作系统进行修改。但是结构应该是一样的

希望对您有所帮助。

关于gradle - 使用 Espresso 运行特定测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20845021/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com