Home | History | Annotate | Download | only in runner
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.test.runner;
     17 
     18 import android.app.Instrumentation;
     19 import android.os.Bundle;
     20 
     21 import com.android.test.runner.junit3.AndroidJUnit3Builder;
     22 import com.android.test.runner.junit4.AndroidJUnit4Builder;
     23 
     24 import org.junit.internal.builders.AllDefaultPossibilitiesBuilder;
     25 import org.junit.runner.Runner;
     26 import org.junit.runners.model.RunnerBuilder;
     27 
     28 /**
     29  * A {@link RunnerBuilder} that can handle all types of tests.
     30  */
     31 class AndroidRunnerBuilder extends AllDefaultPossibilitiesBuilder {
     32 
     33     private final AndroidJUnit3Builder mAndroidJUnit3Builder;
     34     private final AndroidJUnit4Builder mAndroidJUnit4Builder;
     35 
     36     public AndroidRunnerBuilder(boolean canUseSuiteMethod, Instrumentation instr, Bundle bundle,
     37             boolean skipExecution) {
     38         super(canUseSuiteMethod);
     39         mAndroidJUnit3Builder = new AndroidJUnit3Builder(instr, bundle, skipExecution);
     40         mAndroidJUnit4Builder = new AndroidJUnit4Builder(instr, bundle, skipExecution);
     41     }
     42 
     43     @Override
     44     public Runner runnerForClass(Class<?> testClass) throws Throwable {
     45         Runner runner = mAndroidJUnit3Builder.safeRunnerForClass(testClass);
     46         if (runner != null) {
     47             return runner;
     48         }
     49         runner = mAndroidJUnit4Builder.safeRunnerForClass(testClass);
     50         if (runner != null) {
     51             return runner;
     52         }
     53         return super.runnerForClass(testClass);
     54     }
     55 
     56 }
     57