Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
ReactNativeのテスト紹介
Search
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
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
580
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
320
Evolving SEO for Evolving Search Engines
ryanjones
0
300
A better future with KSS
kneath
240
18k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.2k
Making Projects Easy
brettharned
120
6.8k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
360
The SEO Collaboration Effect
kristinabergwall1
1
570
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
840
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
700
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