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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Junki Kaneko
February 03, 2017
1.2k
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
230
Welcome_to_Linter
theoden9014
2
19k
Jenkins のつらみを軽減した話
theoden9014
5
3k
Android SDK with Docker
theoden9014
0
5.9k
Featured
See All Featured
Claude Code のすすめ
schroneko
67
230k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
200
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
230
Odyssey Design
rkendrick25
PRO
2
760
[SF Ruby Conf 2025] Rails X
palkan
2
1.3k
Code Reviewing Like a Champion
maltzj
528
40k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Writing Fast Ruby
sferik
630
63k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
73
41k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
240
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