CI improvements (#695)
parent
bb3b23e69a
commit
859904ec6a
@ -1,17 +0,0 @@ |
|||||||
package com.otaliastudios.cameraview; |
|
||||||
|
|
||||||
import java.lang.annotation.Retention; |
|
||||||
import java.lang.annotation.RetentionPolicy; |
|
||||||
|
|
||||||
/** |
|
||||||
* Thanks to a testInstrumentationRunnerArgument in our build file, we will not |
|
||||||
* execute these tests on Travis CI. |
|
||||||
* The {@link RetentionPolicy#RUNTIME} is needed! |
|
||||||
* |
|
||||||
* https://developer.android.com/reference/android/support/test/runner/AndroidJUnitRunner
|
|
||||||
* |
|
||||||
*/ |
|
||||||
@Retention(RetentionPolicy.RUNTIME) |
|
||||||
public @interface DoNotRunOnTravis { |
|
||||||
String because() default ""; |
|
||||||
} |
|
@ -0,0 +1,18 @@ |
|||||||
|
package com.otaliastudios.cameraview.runner; |
||||||
|
|
||||||
|
import java.lang.annotation.ElementType; |
||||||
|
import java.lang.annotation.Retention; |
||||||
|
import java.lang.annotation.RetentionPolicy; |
||||||
|
import java.lang.annotation.Target; |
||||||
|
|
||||||
|
/** |
||||||
|
* Like {@link androidx.test.filters.SdkSuppress}, but negative. |
||||||
|
*/ |
||||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||||
|
@Target({ElementType.TYPE, ElementType.METHOD}) |
||||||
|
public @interface SdkExclude { |
||||||
|
/** The minimum API level to drop (inclusive) */ |
||||||
|
int minSdkVersion() default 1; |
||||||
|
/** The maximum API level to drop (inclusive) */ |
||||||
|
int maxSdkVersion() default Integer.MAX_VALUE; |
||||||
|
} |
@ -0,0 +1,46 @@ |
|||||||
|
package com.otaliastudios.cameraview.runner; |
||||||
|
|
||||||
|
|
||||||
|
import android.os.Build; |
||||||
|
|
||||||
|
import androidx.annotation.Nullable; |
||||||
|
import androidx.test.internal.runner.filters.ParentFilter; |
||||||
|
|
||||||
|
import org.junit.runner.Description; |
||||||
|
|
||||||
|
/** |
||||||
|
* Filter for {@link SdkExclude}, based on |
||||||
|
* {@link androidx.test.internal.runner.TestRequestBuilder}'s SdkSuppressFilter. |
||||||
|
*/ |
||||||
|
public class SdkExcludeFilter extends ParentFilter { |
||||||
|
|
||||||
|
protected boolean evaluateTest(Description description) { |
||||||
|
final SdkExclude sdkSuppress = getAnnotationForTest(description); |
||||||
|
if (sdkSuppress != null) { |
||||||
|
if (Build.VERSION.SDK_INT >= sdkSuppress.minSdkVersion() |
||||||
|
&& Build.VERSION.SDK_INT <= sdkSuppress.maxSdkVersion()) { |
||||||
|
return false; // exclude the test
|
||||||
|
} |
||||||
|
return true; // run the test
|
||||||
|
} |
||||||
|
return true; // no annotation, run the test
|
||||||
|
} |
||||||
|
|
||||||
|
@Nullable |
||||||
|
private SdkExclude getAnnotationForTest(Description description) { |
||||||
|
final SdkExclude s = description.getAnnotation(SdkExclude.class); |
||||||
|
if (s != null) { |
||||||
|
return s; |
||||||
|
} |
||||||
|
final Class<?> testClass = description.getTestClass(); |
||||||
|
if (testClass != null) { |
||||||
|
return testClass.getAnnotation(SdkExclude.class); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String describe() { |
||||||
|
return "Skip tests annotated with SdkExclude"; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue