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:
Add this to your
build.gradle
:Now, you can execute a specific class with a command like so:
Next, create a file at the root of your Android project:
runAllTests.sh
Edit your
.sh
to look like this:Then, give the script permissions
cd
to the scriptchmod u+x runAllTest.sh
You're set. Now just
cd
to your root, then to execute your test, type. runAllTest.sh
.So, what this does:
result
folder in the root of your project if it is not already there.Results-SOME-DATE
.NOTE: This script was wrote for MAC. If your on windows or anything else, this script may need modifications.
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 yourbash_profile
:Now,
cd
in terminal to theResults-SOME-DATE
, and typeopen-results
. Again, this was written for terminal. You may need to modify depending on your OS. But the structure should be the sameI hope this helps.
The jUnit testing philosophy is that test cases should not depend on each other so order shouldn't be important. That's why you're finding it hard to do. You might want to consider using the "setUp" method to create initial conditions for your test cases rather than having them build on each other.