Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Robolectricの @Configを共通化する方法
Search
えぐ
June 09, 2016
0
810
Robolectricの @Configを共通化する方法
Android Testing Bootcamp #2の発表内容です
えぐ
June 09, 2016
Tweet
Share
More Decks by えぐ
See All by えぐ
KotshiからMoshi-codegenに 乗り換えた経緯
egugue
0
2.2k
Annotationを利用した現在時刻のテスト
egugue
0
830
エンジニアにしてもよいこと エンジニアからお願いしたいこと
egugue
0
170
コードで事前条件を表明する
egugue
3
3.3k
Backends for Frontends を適用した話
egugue
1
1.1k
FlexboxLayoutの紹介
egugue
2
300
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
225
22k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Teambox: Starting and Learning
jrom
131
8.7k
Intergalactic Javascript Robots from Outer Space
tanoku
268
26k
Raft: Consensus for Rubyists
vanstee
135
6.5k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
123
18k
Typedesign – Prime Four
hannesfritz
39
2.3k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
663
120k
Agile that works and the tools we love
rasmusluckow
327
20k
Speed Design
sergeychernyshev
21
420
What’s in a name? Adding method to the madness
productmarketing
PRO
21
3k
Transcript
Robolectricͷ @ConfigΛڞ௨Խ͢Δํ๏ Android Testing Bootcamp #2 2016/6/9
ࣗݾհ • ֎ࢁ ࣏༝ (@duane0728) • Ϡϑʔגࣜձࣾ • Yahoo JapanΞϓϦ୲
ҙ Robolectric3.1ΛͬͨʹͳΓ·͢
ҰൠతͳRobolectricͷ͍ํ
@RunWith(RobolectricGradleTestRunner.class) @Config( sdk = 23, constants = BuildConfig.class ) public
class ExampleUnitTest { @Test public void addition_isCorrect() throws Exception { assertEquals(4, 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); } }
@RunWith(RobolectricGradleTestRunner.class) @Config( sdk = 23, constants = BuildConfig.class ) public
class ExampleUnitTest { @Test public void addition_isCorrect() throws Exception { assertEquals(4, 2 + 2); } }
• ςετΫϥεΛ࡞͢Δͨͼʹ@ConfigΛࢦఆ͢Δͷ໘ • ࢦఆͨͯ͢͠ͷ@ConfigͷઃఆΛมߋ͍ͨ͠߹ɺ ͯ͢ͷςετΫϥεΛमਖ਼ • @Configͷࢦఆํ๏͕มΘͬͯ͠·ͬͨ߹ɺ ͯ͢ͷςετΫϥεΛमਖ਼ 2ܥ͔Β3ܥͰมΘΓ·ͨ͠
@ConfigͷΛڞ௨Խ͍ͨ͠
ํ๏ - 1 ϑΝΠϧʹΓग़͢
ํ๏ - 1 • ެ͕ࣜఏڙ͍ͯ͠ΔΈΛར༻͢Δ http://robolectric.org/configuring/
sdk=23 constants=com.htoyama.robolectricconfigshare.BuildConfig robolectric.properties ͱ͍͏ϑΝΠϧΛ࡞
app/src/test/resources ʹϑΝΠϧΛஔ͘
@RunWith(RobolectricGradleTestRunner.class) @Config( sdk = 23, constants = BuildConfig.class ) public
class ExampleUnitTest { @Test public void addition_isCorrect() throws Exception { assertEquals(4, 2 + 2); } }
@RunWith(RobolectricGradleTestRunner.class) public class ExampleUnitTest { @Test public void addition_isCorrect()
throws Exception { assertEquals(4, 2 + 2); } }
ํ๏ - 2 ςετϥϯφʔΛ࡞͢Δ
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 ); } }
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 ); } }
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 ); } }
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 ); } }
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 ); } }
@RunWith(RobolectricGradleTestRunner.class) @Config( sdk = 23, constants = BuildConfig.class ) public
class ExampleUnitTest { @Test public void addition_isCorrect() throws Exception { assertEquals(4, 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); } }
@RunWith(RobolectricCustomRunner.class) @Config( sdk = 23, constants = BuildConfig.class ) public
class ExampleUnitTest { @Test public void addition_isCorrect() throws Exception { assertEquals(4, 2 + 2); } }
@RunWith(RobolectricCustomRunner.class) @Config( sdk = 23, constants = BuildConfig.class ) public
class ExampleUnitTest { @Test public void addition_isCorrect() throws Exception { assertEquals(4, 2 + 2); } }
@RunWith(RobolectricCustomRunner.class) public class ExampleUnitTest { @Test public void addition_isCorrect()
throws Exception { assertEquals(4, 2 + 2); } }
·ͱΊ
• ࠓޙͷӡ༻ߟ͑ͯ@Configͷઃఆڞ௨Խͤ͞Δ • ڞ௨Խͤ͞Δํ๏2ͭ • ϑΝΠϧʹΓग़͢ • ςετϥϯφʔΛ࡞͢Δ
αϯϓϧίʔυ https://github.com/egugue/RobolectricConfigShare