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
820
Robolectricの @Configを共通化する方法
Android Testing Bootcamp #2の発表内容です
えぐ
June 09, 2016
Tweet
Share
More Decks by えぐ
See All by えぐ
KotshiからMoshi-codegenに 乗り換えた経緯
egugue
0
2.3k
Annotationを利用した現在時刻のテスト
egugue
0
840
エンジニアにしてもよいこと エンジニアからお願いしたいこと
egugue
0
170
コードで事前条件を表明する
egugue
3
3.4k
Backends for Frontends を適用した話
egugue
1
1.1k
FlexboxLayoutの紹介
egugue
2
310
Featured
See All Featured
How to Ace a Technical Interview
jacobian
276
23k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
450
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
KATA
mclloyd
29
14k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Thoughts on Productivity
jonyablonski
67
4.4k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Rails Girls Zürich Keynote
gr2m
94
13k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Fireside Chat
paigeccino
34
3.1k
Code Reviewing Like a Champion
maltzj
520
39k
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