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
Mocha testing in Titanium(ja)
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Kosuke Isobe
August 03, 2015
Programming
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Mocha testing in Titanium(ja)
Kosuke Isobe
August 03, 2015
More Decks by Kosuke Isobe
See All by Kosuke Isobe
React Native で LDR の クライアントを作ったというお話
k0sukey
0
110
Mocha testing in Titanium(en)
k0sukey
1
160
Titanium もくもく会 #11
k0sukey
0
230
Titanium もくもく会 #10
k0sukey
0
2.3k
Titanium もくもく会 #5
k0sukey
0
2k
Other Decks in Programming
See All in Programming
AI駆動開発にグラフDBを重ねてみた
satoshi256kbyte
2
720
新卒PdEのリアル
ryu1013
1
360
信頼性の目標を誰も求めてない
shubox
0
490
バグを直したら useEffect が消えた
colorful12
3
830
高専、大学編入、そして未踏へ〜プロダクト開発とキャリアの歩み - Technical College, University Transfer, and On to “Mitou” / My Journey in Product Development and Career
pkmiya
0
130
AIは賢い。でも実行環境は? CLIおじさんがAI時代に伝えたいこと ~ CLIおじさんがAI時代に伝えたいこと ~
curekoshimizu
1
140
Discordを用いたラボオートメーション関連情報収集の自動化
noguhiro2002
0
500
初めての模倣学習とVLA
natsutan
0
460
이 함수, 실패하면 어떻게 되나요? null부터 Rich Errors까지, Kotlin 에러 처리 15년
haeti2
0
130
20260828_品質と開発生産性を両立させる、AI時代のE2Eテストの考え方
magicpod
0
140
Foundry Localでエージェント開発
seosoft
0
120
GKE アップグレード前に知っておきたい Blue/Green と PDB の関係
stkk
0
140
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
490
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
290
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
720
How to make the Groovebox
asonas
2
2.4k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
The Cult of Friendly URLs
andyhume
79
7k
Chasing Engaging Ingredients in Design
codingconduct
0
300
Bash Introduction
62gerente
615
220k
Music & Morning Musume
bryan
47
7.4k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Transcript
.PDIBUFTUJOH JO5JUBOJVN
ү෦྄ʢ͍ͦ͜͏͚͢ʣ 4PDLFUCBTF*ODɹ$50$PGPVOEFS ȍ ɹ LTVLFZ ͜͡͠ΐ͏͔͍
͜͡͠ΐ͏͔͍ w "MMPZϓϩδΣΫτͷ։ൃΛͪΐͬͽΓָʹ ͢Δ LTVLFZBMMPZTNFMUFS w ࡶʹͳΓ͍͢UTTΛ͖Ε͍ྻ͢͠ LTVLFZUTTGPSNBUUFS ͳΜ͔Λ࡞͍ͬͯ·͢
5JUBOJVNɺςετ ͍ͯ͠·͔͢ʁ
Titanium ͷςετͱ͍͑ w ༰қʹςετͰ͖ͳ͍ w γϛϡʢΤϛϡʣϨʔλʗ࣮ػ͡Όͳ͍ͱςετͰ͖ͳ͍ w "QQDFMFSBUPS1MBUGPSNͷςετߴֹɻ͜Εɺ6* "VUPNBUJPOΛϦϞʔτͰಈ͔ͯ͠Α͏ͳͷͩ͠ w
Ϣχοτςετ͕͍ͨ͠ΜͰ͢ w ͭ·Γɺ༰қʹςετͰ͖ͳ͍
͜Ε͘Β͍ͳΒ w KTIJOU w KTCFBVUJpFS w ςετ͡Όͳͯ͘จ ๏νΣοΫͰ͢Ͷ // gulplfile.js
var gulp = require(‘gulp’), plugin = require(‘gulp—load—plugins’)(); gulp.task(‘jshint’, function(){ return gulp.src(‘app/controllers/**/ *.js’) .pipe(plugin.jshint()) .pipe(plugin.jshint.reporter(‘jshint— stylish’)) .pipe(plugin.jshint.reporter(‘fail’)); }); gulp.task(‘jsbeautifier’, function(){ return gulp.src(‘app/controllers/**/ *.js’) .pipe(plugin.jsbeautifier({ logSuccess: false, mode: ‘VERIFY_ONLY’ })); });
΅͘5JUBOJVNίʔυͷ Ϣχοτςετ͕͍ͨ͠ʂ
Titanium ͷςετͱ͍͑ w UJNPDIB w UJUBOJVNKBTNJOF w UJP w %SJMMCJU
γϛϡʢΤϛϡʣϨʔλʗ࣮ػ ͡Όͳ͍ͱςετͰ͖ͳ͍ λʔϛφϧͰ͍݁ͨ͠Ͱ͢ʜ
ͳͥͰ͖ͳ͍ͷ͔ w ͦͦରͷ࣮ߦڥʢ/PEFKTʣʹ5JUBOJVN"1*͕ ͳ͍Ͱ͢͠ w ਓͷख͕հࡏͯ͠ྑ͍ͷ͔ɻશࣗಈԽ͍ͨ͠ w .BD͡Όͳ͍ͱJ04ͷςετ͕ʜ w 5JUBOJVN4%,("͔Β8JOEPXT1IPOF͖
·ͨ͠Ͷɻ8JOEPXT͍࣋ͬͯͳ͍Ͱ͢
5SBWJT$*ͱ͔$JSDMF$*Ͱ ࠓ෩ʹ$*͍ͨ͠ΜͰ͢ ָ͍ͨ͠
࡞Γ·ͨ͠
ΞʔΩςΫνϟ w /PEFKTͷ7.Ϟδϡʔϧ w 5JUBOJVN"1*Λಈ͔͢ʢೝࣝͤ͞Δʣ w ΈΜͳେ͖.PDIB
7.Ϟδϡʔϧͱ
VM Ϟδϡʔϧ w ؆୯ʹݴ͏ͱɺ҆શͳFWBM w αϯυϘοΫεͳίϯςΩετΛ࡞Γɺͦͷ தͰ+BWB4DSJQUΛ࣮ߦͰ͖Δ w ͦͦFYQPSUTͱ͔SFRVJSF͑͞ແ͍
VM Ϟδϡʔϧ w ͜Μͳײ͡Ͱ࣮ߦڥ Λ࡞ͬͯ͋͛·͢ w WNSVO*O$POUFYUͷ ฦ٫࣮ߦ݁Ռͷί ϯςΩετ˺Ξαʔ γϣϯͰ͖Δ͡Όͳ͍
var vm = require(‘vm’), context = vm.createContext({ require: require, module: module, exports: exports, console: console, setTimeout: setTimeout, setInterval: setInterval, clearTimeout: clearTimeout, clearInterval: clearInterval, JSON: JSON, alert: function(e) { console.log(e); } }), result = vm.runInContext(‘console.log(\’ Hello, world.\’);’, context);
VM Ϟδϡʔϧ w WNDSFBUF$POUFYUʹ 5JUBOJVN"1*Λͯ͠ ͋͛Ε࣮ߦͰ͖Δʁ w Ͳ͏ߟ͑ͯಈ͖·͢ ΑͶɺ͜ΕɻΑ͠ɺ5Jʙ ͳ"1*શ෦ॻ͔͘ʜ
var vm = require(‘vm’), context = vm.createContext({ Ti: { UI: { createWindow: function(){} } } }), result = vm.runInContext(‘var win = Ti.UI.createWindow();’, context);
શ5JUBOJVN"1*Λ Ͳ͏ʹ͔͢Δ
Titanium API w ͦͦɺ͍ͭ͋͘Δͷ͔ղΒͳ͍Ϩϕϧ w ΓΦϒδΣΫτͰ͝·͔ͤͳ͍ w શ෦खॻ͖ࢮϑϥά w ϦϑΝϨϯεΛεΫϨΠϐϯά͢Δ͔ʁ
Titanium API w ެࣜϦϑΝϨϯε͋ Γ·͢ΑͶ w Αʔʔʔ͘ݟͯΒ ͍͍ͨɻ͜ͷล
ϦϑΝϨϯε͕+40/Ͱ ఏڙ͞Ε͍ͯΔʂʂʂ̍
Titanium API w ϦϑΝϨϯε+40/Λͬͯ/PEFKTͷ࣮ ߦڥͰಈ͘5JUBOJVNGBLFS"1*Λࣗಈੜ ͠·͢ w ͍ͭ͜Λ7.ϞδϡʔϧͷίϯςΩετʹ ͯ͠͠·͑ʜ
/PEFKT্Ͱ5JUBOJVNͷ ίʔυ͕࣮ߦͰ͖·ͨ͠❤
ti-slag w 5JUBOJVNGBLFS"1* w 5JUBOJVN4%,͕ଘࡏ͠ͳͯ͘/PEFKT্Ͱ 5JUBOJVN"1*ͷৼΔ͍ΛγϛϡϨʔτ͠·͢ w %FQSFDBUFEͳϓϩύςΟʗϝιουΛ͓৮Γ͢Δͱɺ ྫ֎͕͛ΒΕ·͢ w
ͪΖΜը໘ભҠ͠·ͤΜΑɻը໘ͳ͍Ͱ͢͠
slagʁ w ߭ᕥʢ͜͏͍͞ʣɻ߭ੴ͔Βਫ਼࿉͢Δࡍʹɺ ରͷۚଐ͔Βͨ߭͠ͳͲɻଏʹ ۚሬʢΟΩϖσΟΞௐʣ w ͭ·ΓɺΓΧε
LTVLFZUJTMBH
Mocha testing in ti-slag w ඞཁͳOQNύοέʔ δΛΠϯετʔϧ w QBDLBHFKTPOς ετͷ࣮ߦεΫϦϓ
τΛՃ $ cd path/to/yourapp $ npm init $ npm install mocha ti—slag lodash ——save—dev package.json { … “scripts”: { “test”: “mocha test.js” }, … }
Mocha testing in ti-slag w ·ͣ"MMPZίϯύΠ ϧ͠·͢ɻUJCVJMEʗ BQQDSVOͱ͔Ͱ0,ɻ ͱʹ͔͘3FTPVSDF ԼʹίʔυΛు͔ͤ·͢
w ͦͯ͠OQNUFTU $ alloy compile ——config platform=ios $ npm test >
[email protected]
test /Users/ Kosuke/src/sandbox > mocha test.js iOS index.js ✓ should does not throw exception in the Controller 1 passing (10ms)
Mocha testing in ti-slag w "MMPZϓϩδΣΫτίϯύΠϧ͞ΕΔͱɺ3FTPVSDFTԼ ʹΫϥγοΫͳίʔυΛు͖ग़͠·͢ w ͜ͷίʔυΛUJTMBHʹ͢ͱ7.ڥͰ࣮ߦ͞Εɺ݁ՌΛ ίϯςΩετͱͯ͠ฦ٫͠·͢
w ίϯύΠϧ͞Εͨ"MMPZίϯτϩʔϥNPEVMFFYQPSUTͰ $POUSPMMFSͱͯ͠ެ։͞Ε͍ͯΔͷͰɺ͍ͭ͜Λ࣮ߦ͠·͢
// Resources/…/index.js function Controller() { function doClick() { var next
= Alloy.createController(‘next’ ), view = next.getView(); view.open(); } $.index.open(); } module.exports = Controller; // app/controllers/index.js function doClick() { var next = Alloy.createController(‘next’) , view = next.getView(); view.open(); } $.index.open(); Mocha testing in ti-slag
Mocha testing in ti-slag // test.js var _ = require(‘lodash’),
assert = require(‘assert’), path = require(‘path’), slag = require(‘ti—slag); describe(‘iOS index.js’, function(){ var context = slag(‘./Resources/iphone/alloy/controllers/index.js’, { titanium: ‘4.0.0.GA’, platfrom: ‘ios’, module: { alloy: alloy, ‘alloy/controllers/BaseController’: BaseController } }); it(‘should does not throw exception in the Controller’, function(){ assert.doesNotThrow(function(){ context.Controller(); }); }); });
5JUBOJVN"1*ྑ͍͚Ͳɺ ϞδϡʔϧͲ͏͢ΔͷΑ
Mocha testing in ti-slag w ୈೋҾʹ͋ΔNPEVMF Ͱϐϯͱ͖͔ͨ͠Ε· ͤΜͶ w SFRVJSF͢ΔϞδϡʔϧ
ͷ໊শΛͤͦͷ·· ಡΈࠐ·ΕΔͷͰɺ͓ ͖ʹͲ͏ͧ var context = slag(‘./ Resources/iphone/alloy/ controllers/index.js’, { titanium: ‘4.0.0.GA’, platfrom: ‘ios’, module: { ‘ti.map’: { // ࣗͰ͕ΜΕ } } });
ͦͦ"MMPZͷ࣮ߦڥ Ͳ͏ͳ͍ͬͯΔͷ
Mocha testing in ti-slag w "MMPZͬͯ5JUBOJVN4%,ڥԼͰಈ͍͍ͯ·͢ΑͶ w ͪΖΜUJTMBHڥԼͰಉ͡Α͏ʹ࣮ߦͰ͖·͢ w UJTMBHͷϞδϡʔϧʹ"MMPZίϯςΩετΛͯ͋͛͠
Ε0,Ͱ͢ʢਖ਼͘͠#BTF$POUSPMMFSඞཁͰ͢ʣ w ৄ͘͠ɺ LTVLFZUJTMBHUFTUKTΛࢀর
είʔϓతʹߟ͑ͯ EP$MJDL͕࣮ߦͰ͖ͳ͍
Mocha testing in ti-slag w UJTMBHʹ"MMPZίϯςΩ ετ͕ల։͞Ε͍ͯΔͷͰɺ "MMPZίϯτϩʔϥͷϝιο υͦͷ··͑Δ w
"MMPZ!͔ΒՃ͞Ε ͨΠϕϯτՃʗऔಘʗআ ϝιουͰΠϕϯτϦεφΛ औಘ͢Ε0, assert.doesNotThrow(function(){ context.Controller(); var listeners = context.getListener(); });
Mocha testing in ti-slag describe(‘iOS index.js’, function(){ var context =
slag(‘./Resources/iphone/alloy/controllers/index.js’, { titanium: ‘4.0.0.GA’, platfrom: ‘ios’, module: { alloy: alloy, ‘alloy/controllers/BaseController’: BaseController } }), listeners; it(‘should does not throw exception in the Controller’, function(){ assert.doesNotThrow(function(){ context.Controller(); listeners = context.getListener(); }); }); it(‘should does not throw exception in the event listeners’, function(){ assert.doesNotThrow(function(){ _.each(listeners, function(listener){ listener.handler(); }); }); }); });
$JSDMF$*ͷ࣮ߦڥΛ ఆٛ͠·͢
circle.yml w UFTUQSFͰHVMQ KTIJOUKTCFBVUJpFS ͔ͯ͠Β"MMPZίϯ ύΠϧ w ͦͷίϯύΠϧ݁ՌΛ ࣋ͬͯςετΛ࣮ߦ machine:
node: version: 0.10.34 dependencies: pre: — npm install —g alloy — npm install test: pre: — gulp jshint — gulp jsbeautifier — alloy compile ——config platform=ios — alloy compile ——config platform=android
(JU)VCʹϓογϡ $JSDMF$*Ͱ࣮ߦ ݁ՌΛ4MBDLʹ ͛Δ ɹɹɹɹɹɹɹɹɹɹ΅͘͝ຬӻ CI
5IBOLZPV❤
2VFTUJPOʁ