public final class

TestsRegExFilter

extends ParentFilter

 java.lang.Object

↳Filter

androidx.test.internal.runner.filters.ParentFilter

↳androidx.test.internal.runner.filters.TestsRegExFilter

Gradle dependencies

compile group: 'androidx.test', name: 'runner', version: '1.5.0-alpha03'

  • groupId: androidx.test
  • artifactId: runner
  • version: 1.5.0-alpha03

Artifact androidx.test:runner:1.5.0-alpha03 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test:runner com.android.support.test:runner

Overview

A JUnit filter for filtering tests whose name match one of the given regular expression

Summary

Constructors
publicTestsRegExFilter()

Methods
public java.lang.Stringdescribe()

protected abstract booleanevaluateTest(Description description)

Determine if given test description matches filter.

public voidsetPattern(java.lang.String patternString)

Sets the regex pattern to use

from ParentFiltershouldRun
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public TestsRegExFilter()

Methods

public void setPattern(java.lang.String patternString)

Sets the regex pattern to use

protected abstract boolean evaluateTest(Description description)

Determine if given test description matches filter.

Parameters:

description: the describing the test

Returns:

true if matched

public java.lang.String describe()

Source

/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.test.internal.runner.filters;

import java.util.regex.Pattern;
import org.junit.runner.Description;

/** A JUnit filter for filtering tests whose name match one of the given regular expression */
public final class TestsRegExFilter extends ParentFilter {

  private Pattern pattern = null;

  /** Sets the regex pattern to use */
  public void setPattern(String patternString) {
    this.pattern = Pattern.compile(patternString);
  }

  @Override
  protected boolean evaluateTest(Description description) {
    if (pattern == null) {
      return true;
    }
    String testName =
        String.format("%s#%s", description.getClassName(), description.getMethodName());
    return pattern.matcher(testName).find();
  }

  @Override
  public String describe() {
    return "tests filter";
  }
}