A really nasty workaround is to override the getName method on the
test class:
@Override
public String getName()
{
for (StackTraceElement stackElement :
Thread.currentThread().getStackTrace())
{
if
(stackElement.getClassName().equals("android.test.InstrumentationTestRunner
$WatcherResultPrinter"))
{
if (stackElement.getMethodName().equals("startTest"))
{
return "bugFix";
}
}
}
return super.getName();
}
and to declare a method called "bugFix" in the class. This allows the
test to run but the test names in eclipse all come up as bugfix.
On Apr 28, 11:07 am, alan <[email protected]> wrote:
> When defining a junit test using the static suite method android
> assumes that the name of each test is also the name of a method. If
> this is not the case then the test runner fails to run. The following
> test class works correctly using the standard eclipse junit runner:
>
> public class CustomTest extends TestCase
> {
>
> public CustomTest(String testName)
> {
> super(testName);
> }
>
> @Override
> protected void runTest() throws Throwable
> {
> Assert.fail("Test failed");
> }
>
> public static Test suite()
> {
> TestSuite suite = new TestSuite();
> suite.addTest(new CustomTest("test1"));
> return suite;
> }
>
> }
>
> however running using the android test runner says that test1 passes!
> I have managed to trace this down to the following code in
> InstrumentationTestRunner:
> try {
> // Look for TimedTest annotation on both test class
> and test method
> if
> (test.getClass().getMethod(testName).isAnnotationPresent(TimedTest.class))
> {
> mIsTimedTest = true;
> mIncludeDetailedStats =
> test.getClass().getMethod(testName).getAnnotation(
> TimedTest.class).includeDetailedStats();
> } else if
> (test.getClass().isAnnotationPresent(TimedTest.class)) {
> mIsTimedTest = true;
> mIncludeDetailedStats =
> test.getClass().getAnnotation(
> TimedTest.class).includeDetailedStats();
> }
> } catch (SecurityException e) {
> throw new IllegalStateException(e);
> } catch (NoSuchMethodException e) {
> throw new IllegalStateException(e);
> }
> The thrown IllegalStateException doesn't seem to be caught or reported
> anywhere which is I think why the eclipse plugin incorrectly reports
> the tests have passed. As this code is called before the test is run
> the test code is never called.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group
> athttp://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en