如何在 Android 中为 Spoon 自动化测试订购测试用例? [英] How to order test cases for Spoon Automated Testing in Android?

查看:24
本文介绍了如何在 Android 中为 Spoon 自动化测试订购测试用例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一个 suite() 方法来按照我想要的方式对我的测试进行排序,因此当我通过 Android JUnit 运行它时,它们会相应地执行.但后来我注意到,当我使用 Spoon 执行时,使用 cmd 的执行,我的测试用例按字母顺序执行,这是默认顺序.

I have added a suite() method to order my tests the way I want them and thus when I run it through Android JUnit they are executed accordingly. But then I noticed that when I use the Spoon execution, the one using cmd, my test cases are executed alphabetically which is the default order.

为什么会发生这种情况?如果不重命名我的测试用例,您将如何应对?

Why does this happen and how would you counter it without renaming my test cases?

推荐答案

我和你有同样的问题;我需要一个特定的顺序来运行我的测试.我正在测试的应用程序太复杂,无法以不可预测的顺序运行.我的解决方案是这样的:

I have the same issue as you; I require a specific order that my test need to be ran in. The app I am testing is too complicated to run in an unpredictable order. My solution was this:

将此添加到您的 build.gradle:

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

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

gradle 勺子 -PspoonClassName=<com.your.pakage.ClassName>

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

接下来,在您的 Android 项目的根目录下创建一个文件:runAllTests.sh

编辑您的 .sh 使其如下所示:

Edit your .sh to look like this:

 #!/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.

You're set. Now just cd to your root, then to execute your test, type . runAllTest.sh.

那么,这是做什么的:

  1. 首先,它创建一个 timestamp.out.我使用它是为了可以一遍又一遍地将我的结果保存到一个文件中,而不会覆盖以前的结果.你不需要这部分.
  2. 接下来,它会在您的项目的根目录中创建一个 result 文件夹(如果它还没有的话).
  3. 然后,它将在结果文件夹中创建一个名为 Results-SOME-DATE 的文件夹.
  4. 最后,每个测试都会运行,并将结果保存到项目的正常位置.(在 build/spoon 内部)一旦测试完成,它会将结果复制到结果文件夹,并适当地命名每个测试结果,以便轻松查看所有测试的运行情况.
  1. First, it creates a timestamp.out. I use this so I can save my results to a file over and over without previous results being overwritten. You do not need this part.
  2. Next, it creates a result folder in the root of your project if it is not already there.
  3. Then, it will make a folder inside the results folder named Results-SOME-DATE.
  4. Lastly, each test will run, saving the results to the normal spot on your project. (Inside build/spoon) Once test are complete it will copy the results to the results folder, and name each test result appropriately so it is easy to see all your tests ran.

注意:此脚本是为 MAC 编写的.如果您在 Windows 或其他任何设备上,则此脚本可能需要修改.

NOTE: This script was wrote for MAC. If your on windows or anything else, this script may need modifications.

另外:你会发现打开每个文件夹来打开index.html是很不方便的.所以我写了这个脚本来添加到你的 bash_profile:

Additionally: You will find it is inconvenient to open in to each folder to get the index.html opened. So I wrote this script to add to your 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.同样,这是为终端编写的.您可能需要根据您的操作系统进行修改.但是结构应该是一样的

Now, cd in terminal to the Results-SOME-DATE, and type open-results. Again, this was written for terminal. You may need to modify depending on your OS. But the structure should be the same

我希望这会有所帮助.

这篇关于如何在 Android 中为 Spoon 自动化测试订购测试用例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆