Skip to content

Conversation

jan-varecka-signageos-io

Now TestRequestBuilder.CustomFilters does not evaluate @CustomFilter on test classes, just on tests. It will be great to have evaluation also for classes.

Because of this missing feature, I need to apply my annotation with @CustomFilter to every test method, or I have to configure instrumentation runner in build.gradle.kts (or in my custom runner). All these solutions are kind of painful in large multimodule project.

android {
    defaultConfig {
        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        testInstrumentationRunnerArguments["filter"] = listOf(
            "mypackage.MyCustomFilter",
        ).joinToString(separator = ",")
    }
}

or

class MyAndroidJUnitRunner : AndroidJUnitRunner() {

    override fun onCreate(arguments: Bundle) {
        arguments.putString("filter", MyCustomFilter::class.java.name)
        super.onCreate(arguments)
    }
}

Copy link
Collaborator

@brettchabot brettchabot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add an entry to runner/android_junit_runner/CHANGELOG.md

Copy link

@consp1racy consp1racy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm missing a test case where the annotation is both on the class and on the methods, with different values.

true { true, false, none } --> 2

public void testTwoSkip() {}
}

public static class SampleCustomFilterOnClass extends AbstractFilter {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test code esentially simulates consumer code. The consumer shouldn't need to override anything but evaluateTest for this PR to work on classes. And they don't, thanks to the changes in CustomFilters.shouldRun above.

This class shouldn't exist. Usages can be replaced by the existing SampleCustomFilter class.

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@CustomFilter(filterClass = SampleCustomFilterOnClass.class)
public @interface SampleCustomAnnotationOnClass {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This annotation shouldn't exist, it's essentially the same as SampleCustomAnnotation, just below.

@jan-varecka-signageos-io jan-varecka-signageos-io marked this pull request as draft May 2, 2024 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants