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

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

问题描述

我添加了一个套件()方法来订购我的测试中,我想他们的方式。因此,当我运行它通过的Andr​​oid的JUnit 它们相应的执行。但后来我发现,当我用勺子执行,使用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?

推荐答案

我有同样的问题,因为你;我需要一个特定的顺序,我的测试需要先跑去。我测试的应用程序是太复杂,在未predictable顺序运行。我的解决办法是这样的:

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

Add this to your build.gradle:

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

现在,你可以像这样的命令执行特定的类:

勺子的gradle = -PspoonClassName LT&; com.your.pakage.ClassName>

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

接下来,在你的Andr​​oid项目的根目录下创建文件: runAllTests.sh

Next, create a file at the root of your Android project: 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ü+ X runAllTest.sh

  1. cd to the script
  2. type 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。我用这个,所以我可以一遍又一遍我的结果保存到一个文件,而不previous结果被覆盖。你不需要这个部分。

  2. 接下来,它会创建一个结果文件夹中的项目的根,如果它已不存在。

  3. 然后,它会使一个文件夹命名为结果文件夹结果 - 有些-DATE 中。

  4. 最后,每个测试运行,保存结果到您的项目在正常的位置。 (内搭/汤匙)一旦测试完成后,将结果复制到结果文件夹,并为其适当命名每个测试结果,所以很容易地看到所有的测试运行。

  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
 } 

现在, CD 终端到结果 - 有些-DATE ,然后键入开放式结果。再次,这是为终端写入。您可能需要根据您的操作系统进行修改。但结构的的相同

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中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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