3

Update: Turns out that the annotation argument intersects the given filters, If anyone knows how to unify them instead I would be grateful

I'm trying to filter my Espresso tests by annotations. For this purpose, I created 3 Annotations (One, Two & Three) like so:

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface One {
}

And 3 Espresso tests, each with its own annotation like so:

@One
@Test
public void checkDate() {

    String currentMonth;

    // Get current month
    currentMonth = (String)android.text.format.DateFormat.format("MMMM", new Date());

    // Check the month in application is correct
    onView(withId(R.id.textViewMonth)).check(matches(withText(currentMonth)));
}

When I try to run my annotated tests one annotation at a time like so:

adb shell am instrument -w -e annotation "com.playground.appfortesting.One" com.playground.appfortesting.test/androidx.test.runner.AndroidJUnitRunner

Everything works as expected and only 1 test is executed.

Now, according to the Android documentation:

Filter test run to tests with all annotations in a list: adb shell am instrument -w -e annotation com.android.foo.MyAnnotation,com.android.foo.AnotherAnnotation com.android.foo/androidx.test.runner.AndroidJUnitRunner

But when trying to run the command:

adb shell am instrument -w -e annotation com.playground.appfortesting.Three,com.playground.appfortesting.One com.playground.appfortesting.test/androidx.test.runner.AndroidJUnitRunner

No tests are executed.

Any ideas why this is happening or alternatively, suggestions on how to make this work will be greatly appreciated.

zwebie
  • 2,349
  • 1
  • 27
  • 43

0 Answers0