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
ReactNativeのテスト紹介
Search
Junki Kaneko
February 03, 2017
1.1k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ReactNativeのテスト紹介
Junki Kaneko
February 03, 2017
More Decks by Junki Kaneko
See All by Junki Kaneko
DeNA TechCon 2021 - 自動テストのないプロダクトの開発効率化への道
theoden9014
0
220
Welcome_to_Linter
theoden9014
2
18k
Jenkins のつらみを軽減した話
theoden9014
5
3k
Android SDK with Docker
theoden9014
0
5.9k
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
96
14k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
160
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
190
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
GitHub's CSS Performance
jonrohan
1033
470k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2k
So, you think you're a good person
axbom
PRO
2
2.1k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Navigating Weather and Climate Data
rabernat
0
220
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
22k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
150
Transcript
React Native のテスト紹介 February 2, 2017 Junki Kaneko SWET Group
DeNA Co., Ltd.
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Profile
• 名前: 金子 淳貴 ◦ 所属 ▪ DeNA システム部 SWET Group Testinfra Team ◦ 経歴 ▪ インフラ構築運用 / DevOps, CI基盤開発 / QA → テストインフラ開発 ◦ 普段の業務 ▪ UI自動テストシステムの開発 ▪ バージョンアップ自動検証システムの開発
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Agenda
• React Nativeの紹介 • React Native Testing ◦ Unit Test ◦ Integration Test
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. ReactNativeって?
• JavaScriptとReact.jsで Nativeモバイルアプリを開発できるフレームワーク • UIのパーツをUI Componentとして構築していく
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. ReactNativeの特徴
• ライフサイクルを考えなくて良い • iOS / Android のコードを一部共通化できる
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. ReactNative
(Android) • iOSと比べると対応しているLibraryが若干少ない https://js.coach/react-native で検索した結果 • ios : 690 • android : 610
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. ReactNative
Testing • Unit Test : JavaScriptレベルのテストを行う ◦ JEST ◦ Mocha • Integration Test : E2EのUIテスト ◦ Appium
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. JESTの特徴
(UnitTest) • Facebook製のJavaScript Test Framwork • ロジック的なUnitテストだけではなく、 Snapshot Testingが可能
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. JEST
Snapshot Testing (UnitTest) • ReactComponentをJavaScript内でレンダリングし、 以前レンダリングした内容と変わっていないか 確認出来る
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. //
Sample.js import React, {Component} from 'react'; import { Text, View } from 'react-native'; export default class Sample extends Component { render() { return ( <View> <Text> This is Sample </Text> <Text> This is Test </Text> </View> ); } } // __tests__/Sample-test.js import 'react-native'; import React from 'react'; import Sample from '../Sample'; import renderer from 'react-test-renderer'; it('renders correctly', () => { const tree = renderer.create( <Sample /> ).toJSON(); expect(tree).toMatchSnapshot(); }); // __tests__/__snapshots__/Sample.js.snap exports[`test renders correctly 1`] = ` <View> <Text accessible={true} allowFontScaling={true} ellipsizeMode="tail"> This is Sample </Text> <Text accessible={true} allowFontScaling={true} ellipsizeMode="tail"> This is Test </Text> </View> `; Test Code Component Source Code Snapshot generate
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Integration
Test (Android) • AndroidのUI Frameworkで描写されるので、 通常のAndroid Applicationと同様にテストすることが可能 (iOSも同様)
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Integration
Test (Android) • iOS / Android に対応している自動テストツール
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Integration
Test with Appium (Android) ComponentのPropertiesとして、 • accessibilityLabel={'Something'} を指定することによって、 contentDescriptionを埋め込める。
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Integration
Test with Appium (Android) import React, { Component } from 'react'; import { Alert, AppRegistry, Button, Text, View } from 'react-native'; export default class sample extends Component { onButtonPress() { Alert.alert('This is Alert Title', 'Button has been pressed'); } render() { return ( <View accessibilityLabel="sample view"> <Text accessibilityLabel="sample text"> Sample </Text> <Button onPress={this.onButtonPress} title="ALERT" accessibilityLabel="sample button" /> </View> ); } } AppRegistry.registerComponent('sample', () => sample); <?xml version="1.0" encoding="UTF-8"?> … <android.view.ViewGroup index="0" text="" class="android.view.ViewGroup" package="com.sample" content-desc="sample view" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,48][720,156]" resource-id="" instance="0"> ... <android.widget.TextView index="0" text="Sample" class="android.widget.TextView" package="com.sample" content-desc="sample text" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,48][720,86]" resource-id="" instance="0"/> <android.widget.Button index="1" text="" class="android.widget.Button" package="com.sample" content-desc="sample button" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,86][720,156]" resource-id="" instance="0"> <android.widget.TextView index="0" text="ALERT" class="android.widget.TextView" package="com.sample" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" ... Appium (driver.page_source) ReactNative AppCode (index.android.js) PageSource XML
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Integration
Test with Appium (Android) • よって、以下のような指定でElementを検出できる driver.find_element_by_xpath("//*[@content-desc='sample button']")
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Integration
Test with Appium (Android) • Xpathでしか検出できないので信頼性が低い...
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Integration
Test with Appium (Android)
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Integration
Test with Appium (Android) ComponentのPropertiesとして、 • testID={'Something'} を指定することによってtestIDを埋め込める?
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Integration
Test with Appium (Android) • iOSは以下のような指定でElementを検出できるそう なのでAndroidでも試してみる driver.find_element_by_name("Something")
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Integration
Test with Appium (Android) • iOSは以下のような指定でElementを検出できるそう なのでAndroidでも試してみる driver.find_element_by_name("Something")
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Integration
Tes with Appium (Android)
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Integration
Test with Appium (Android) しかし、今現在のAppiumでは AndroidのViewTagを検出することができない...
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Integration
Test with Appium (Android) 開発状況 ReactNative => testIDをresource-idに埋め込むように • https://github.com/facebook/react-native/issues/9777 • https://github.com/facebook/react-native/pull/9942 Appium => ViewTagを検出できるように • https://github.com/appium/appium/issues/6025
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Integration
Test with Appium (Android) 開発状況 ReactNative => testIDをresource-idに埋め込むように • https://github.com/facebook/react-native/issues/9777 • https://github.com/facebook/react-native/pull/9942 Appium => ViewTagを検出できるように • https://github.com/appium/appium/issues/6025
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. Finally
AppiumでAndroidのテストを書くのは もう少し待った方が良さそう
* Copyright (C) 2017 DeNA Co.,Ltd. All Rights Reserved. THANKS
FOR LISTENING