7

I'm trying to write a batched instrumentation test (using ActivityInstrumentationTestCase2) for a particular Activity where I change the intent each time the test runs. I can do this with a single test, and just loop through stopping and restarting the Activity with the new intent, but this is not what I want. One reason is they really should be separate test runs. The other reason is, I'm using Spoon to generate a report when the tests finish, and the report will rightly think I only ran one test.

What I would like is it to treat a single test as a possibly infinite number of tests, and pass the data into the test each time the test runs.

Unfortunately you can't use Theories because it results in a RuntimeException where the InstrumentationTestRunner can't find my tests. Anyone have any luck with this?

Christopher Perry
  • 38,891
  • 43
  • 145
  • 187

2 Answers2

0

You could always just create a "testing" intent. In order to simulate the relaunching of the application, make a method or several methods that reset all your static variables between tests. Then you can test the classes from within a testing intent inside the application itself using

assert("value", MyClass.myMethod);
resetStatics();
assert(true, MyClass,myMethod);
resetStatics();

I don't know how much this will help you, if at all, but this is how I started writing my own tests.

AdamOutler
  • 870
  • 4
  • 13
  • 29
0

I recently discovered that you can add a public static Test suite() method to a test class, and when you run just this single test class, InstrumentationTestRunner will run the Test returned by this method. This is helpful because suite() can explicitly call any constructor of your TestCase, including one with parameters.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268