Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Robolectricの @Configを共通化する方法

えぐ
June 09, 2016
820

Robolectricの @Configを共通化する方法

Android Testing Bootcamp #2の発表内容です

えぐ

June 09, 2016
Tweet

Transcript

  1. @RunWith(RobolectricGradleTestRunner.class)
 @Config(
 sdk = 23,
 constants = BuildConfig.class
 )
 public

    class ExampleUnitTest {
 
 @Test public void addition_isCorrect() throws Exception {
 assertEquals(4, 2 + 2);
 }
 
 }
  2. @RunWith(RobolectricGradleTestRunner.class)
 @Config(
 sdk = 23,
 constants = BuildConfig.class
 )
 public

    class ExampleUnitTest {
 
 @Test public void addition_isCorrect() throws Exception {
 assertEquals(4, 2 + 2);
 }
 
 }
  3. @RunWith(RobolectricGradleTestRunner.class)
 @Config(
 sdk = 23,
 constants = BuildConfig.class
 )
 public

    class ExampleUnitTest {
 
 @Test public void addition_isCorrect() throws Exception {
 assertEquals(4, 2 + 2);
 }
 
 }
  4. @RunWith(RobolectricGradleTestRunner.class)
 @Config(
 sdk = 23,
 constants = BuildConfig.class
 )
 public

    class ExampleUnitTest {
 
 @Test public void addition_isCorrect() throws Exception {
 assertEquals(4, 2 + 2);
 }
 
 }
  5. public class RobolectricCustomRunner extends RobolectricGradleTestRunner {
 private static final int[]

    SDK = new int[]{23};
 
 public RobolectricCustomRunner(Class<?> klass) throws InitializationError {
 super(klass);
 }
 
 @Override public Config getConfig(Method method) {
 Config c = super.getConfig(method);
 
 int[] sdkLevel = c.sdk().length == 0 ? SDK : c.sdk();
 Class<?> constants = c.constants() == Void.class ? BuildConfig.class : c.constants();
 
 return new Config.Implementation(
 sdkLevel,
 c.manifest(), c.qualifiers(), c.packageName(),
 c.abiSplit(), c.resourceDir(), c.assetDir(),
 c.buildDir(), c.shadows(), c.instrumentedPackages(),
 c.application(), c.libraries(),
 constants
 );
 }
 }
  6. public class RobolectricCustomRunner extends RobolectricGradleTestRunner {
 private static final int[]

    SDK = new int[]{23};
 
 public RobolectricCustomRunner(Class<?> klass) throws InitializationError {
 super(klass);
 }
 
 @Override public Config getConfig(Method method) {
 Config c = super.getConfig(method);
 
 int[] sdkLevel = c.sdk().length == 0 ? SDK : c.sdk();
 Class<?> constants = c.constants() == Void.class ? BuildConfig.class : c.constants();
 
 return new Config.Implementation(
 sdkLevel,
 c.manifest(), c.qualifiers(), c.packageName(),
 c.abiSplit(), c.resourceDir(), c.assetDir(),
 c.buildDir(), c.shadows(), c.instrumentedPackages(),
 c.application(), c.libraries(),
 constants
 );
 }
 }
  7. public class RobolectricCustomRunner extends RobolectricGradleTestRunner {
 private static final int[]

    SDK = new int[]{23};
 
 public RobolectricCustomRunner(Class<?> klass) throws InitializationError {
 super(klass);
 }
 
 @Override public Config getConfig(Method method) {
 Config c = super.getConfig(method);
 
 int[] sdkLevel = c.sdk().length == 0 ? SDK : c.sdk();
 Class<?> constants = c.constants() == Void.class ? BuildConfig.class : c.constants();
 
 return new Config.Implementation(
 sdkLevel,
 c.manifest(), c.qualifiers(), c.packageName(),
 c.abiSplit(), c.resourceDir(), c.assetDir(),
 c.buildDir(), c.shadows(), c.instrumentedPackages(),
 c.application(), c.libraries(),
 constants
 );
 }
 }
  8. public class RobolectricCustomRunner extends RobolectricGradleTestRunner {
 private static final int[]

    SDK = new int[]{23};
 
 public RobolectricCustomRunner(Class<?> klass) throws InitializationError {
 super(klass);
 }
 
 @Override public Config getConfig(Method method) {
 Config c = super.getConfig(method);
 
 int[] sdkLevel = c.sdk().length == 0 ? SDK : c.sdk();
 Class<?> constants = c.constants() == Void.class ? BuildConfig.class : c.constants();
 
 return new Config.Implementation(
 sdkLevel,
 c.manifest(), c.qualifiers(), c.packageName(),
 c.abiSplit(), c.resourceDir(), c.assetDir(),
 c.buildDir(), c.shadows(), c.instrumentedPackages(),
 c.application(), c.libraries(),
 constants
 );
 }
 }
  9. public class RobolectricCustomRunner extends RobolectricGradleTestRunner {
 private static final int[]

    SDK = new int[]{23};
 
 public RobolectricCustomRunner(Class<?> klass) throws InitializationError {
 super(klass);
 }
 
 @Override public Config getConfig(Method method) {
 Config c = super.getConfig(method);
 
 int[] sdkLevel = c.sdk().length == 0 ? SDK : c.sdk();
 Class<?> constants = c.constants() == Void.class ? BuildConfig.class : c.constants();
 
 return new Config.Implementation(
 sdkLevel,
 c.manifest(), c.qualifiers(), c.packageName(),
 c.abiSplit(), c.resourceDir(), c.assetDir(),
 c.buildDir(), c.shadows(), c.instrumentedPackages(),
 c.application(), c.libraries(),
 constants
 );
 }
 }
  10. @RunWith(RobolectricGradleTestRunner.class)
 @Config(
 sdk = 23,
 constants = BuildConfig.class
 )
 public

    class ExampleUnitTest {
 
 @Test public void addition_isCorrect() throws Exception {
 assertEquals(4, 2 + 2);
 }
 
 }
  11. @RunWith(RobolectricGradleTestRunner.class)
 @Config(
 sdk = 23,
 constants = BuildConfig.class
 )
 public

    class ExampleUnitTest {
 
 @Test public void addition_isCorrect() throws Exception {
 assertEquals(4, 2 + 2);
 }
 
 }
  12. @RunWith(RobolectricCustomRunner.class)
 @Config(
 sdk = 23,
 constants = BuildConfig.class
 )
 public

    class ExampleUnitTest {
 
 @Test public void addition_isCorrect() throws Exception {
 assertEquals(4, 2 + 2);
 }
 
 }
  13. @RunWith(RobolectricCustomRunner.class)
 @Config(
 sdk = 23,
 constants = BuildConfig.class
 )
 public

    class ExampleUnitTest {
 
 @Test public void addition_isCorrect() throws Exception {
 assertEquals(4, 2 + 2);
 }
 
 }