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.3k
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
Facilitating Awesome Meetings
lara
50
6.1k
Teambox: Starting and Learning
jrom
133
8.8k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Speed Design
sergeychernyshev
25
620
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
Documentation Writing (for coders)
carmenintech
65
4.4k
Docker and Python
trallard
40
3.1k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Being A Developer After 40
akosma
87
590k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
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