public class

NonLeakyTestSuite

extends TestSuite

 java.lang.Object

↳TestSuite

↳androidx.test.internal.runner.junit3.NonLeakyTestSuite

Gradle dependencies

compile group: 'androidx.test', name: 'runner', version: '1.6.2'

  • groupId: androidx.test
  • artifactId: runner
  • version: 1.6.2

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

Androidx artifact mapping:

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

Overview

A that discards references to included tests when execution is complete. Done so tests can be garbage collected and memory freed.

Summary

Constructors
publicNonLeakyTestSuite(java.lang.Class<java.lang.Object> testClass)

Methods
public voidaddTest(Test test)

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

Constructors

public NonLeakyTestSuite(java.lang.Class<java.lang.Object> testClass)

Methods

public void addTest(Test test)

Source

/*
 * Copyright (C) 2014 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.junit3;

import junit.framework.Test;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import org.junit.Ignore;
import org.junit.runner.Describable;
import org.junit.runner.Description;

/**
 * A {@link TestSuite} that discards references to included tests when execution is complete. Done
 * so tests can be garbage collected and memory freed.
 */
@Ignore
public class NonLeakyTestSuite extends TestSuite {
  public NonLeakyTestSuite(Class<?> testClass) {
    super(testClass);
  }

  @Override
  public void addTest(Test test) {
    super.addTest(new NonLeakyTest(test));
  }

  private static class NonLeakyTest implements Test, Describable {
    private Test delegate;
    private final Description desc;

    NonLeakyTest(Test delegate) {
      this.delegate = delegate;
      // cache description so it's available after execution
      this.desc = JUnit38ClassRunner.makeDescription(this.delegate);
    }

    @Override
    public int countTestCases() {
      if (delegate != null) {
        return delegate.countTestCases();
      } else {
        return 0;
      }
    }

    @Override
    public void run(TestResult result) {
      delegate.run(result);
      delegate = null;
    }

    @Override
    public Description getDescription() {
      return desc;
    }

    @Override
    public String toString() {
      if (delegate != null) {
        return delegate.toString();
      } else {
        return desc.toString();
      }
    }
  }
}