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
UnitTest Anti-Pattern
Search
Shoma Suzuki
January 30, 2018
Technology
2
1.8k
UnitTest Anti-Pattern
こんなUnitTest はイヤだ
~ 対策を添えて ~
Shoma Suzuki
January 30, 2018
Tweet
Share
More Decks by Shoma Suzuki
See All by Shoma Suzuki
Feedback Loops in Development
shomas
1
510
品質への取り組み
shomas
2
5.7k
メルカリにおける Software Engineer in Test
shomas
5
8.6k
Other Decks in Technology
See All in Technology
RAGのサービスをリリースして1年3ヶ月が経ちました
segavvy
4
960
コミュニティサービスに「あなたへ」フィードを リリースするまでの試行錯誤
takapy
1
150
楽しくGoを学び合う、LayerXの勉強会文化 / LayerX's study culture of having fun and learning Go together
ar_tama
2
350
データベース研修 分析向けSQL入門【MIXI 24新卒技術研修】
mixi_engineers
PRO
0
110
大規模ドラレコデータ収集・機械学習基盤を支える AWS CDK 〜導入・運用事例紹介〜
pemugi
0
110
Azure OpenAI Service Dev Day / LLMでできる!使える!生成AIエージェント
masahiro_nishimi
3
810
シフトレフトで挑む セキュリティの生産性向上
sekido
PRO
0
270
エンジニアリングマネージャーはどう学んでいくのか #devsumi / How Do Engineering Managers Continue to Learn and Grow?
expajp
4
1.3k
DevIO2024_レガシー運用からの脱却 -クラウド活用の実践事例とベストプラクティス-
jun2882
0
210
Azure AI ことはじめ
tsubakimoto_s
0
130
E2Eテスト自動化プラットフォームにおけるAIの活用
shift_evolve
0
190
サービス開発を前に進めるために 新米リードエンジニアが 取り組んだこと / Steps Taken by a Novice Lead Engineer to Advance Service Development
nologyance
0
180
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
224
21k
Build your cross-platform service in a week with App Engine
jlugia
227
17k
VelocityConf: Rendering Performance Case Studies
addyosmani
321
23k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
277
13k
KATA
mclloyd
20
13k
YesSQL, Process and Tooling at Scale
rocio
166
14k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
17
8.7k
What’s in a name? Adding method to the madness
productmarketing
PRO
21
2.9k
Designing the Hi-DPI Web
ddemaree
276
34k
How To Stay Up To Date on Web Technology
chriscoyier
784
250k
Become a Pro
speakerdeck
PRO
15
4.8k
Done Done
chrislema
179
15k
Transcript
UnitTest Anti-Pattern 2018/01/30 BPStudy#125 Shoma Suzuki
About Me • Software Engineer in Test at Mercari •
github/twitter -> shoma • ։ൃ/ςετڥΛඋͨ͠Γ • CI ઃఆͨ͠Γ • ςετॻ͍ͨΓ • build Λͨ͠Γ • ٕज़తෛ࠴ͱ͖߹ͬͨΓ
For Disclaimer • xUnit Test Patterns xunitpatterns.com • Unit testing
Anti-patterns catalogue • stackoverflow.com/questions/333682/unit-testing-anti- patterns-catalogue • [༁] joker1007.hatenablog.com/entry/20130709/ 1373365053 • TddAntiPatterns www.hyuki.com/yukiwiki/wiki.cgi?TddAntiPatterns (ݪจ 404 NotFound) ʹ͍͍ͩͨॻ͍ͯ͋Γ·͢
͜ΜͳUnitTest ΠϠͩ ~ ରࡦΛఴ͑ͯ ~
1. Assertion ͕ແ͍ @Test public testSomething() { arrangeCondition(); sut.theMethod(); }
1. Assertion ͕ແ͍ • [ݪҼ] ྫ֎͕ग़ͳ͚Ε͍͍/ಈ͔͚ͩ͢Ͱςετͨͭ͠ Γ • [ରࡦ] PMD
JUnitTestsShouldIncludeAssert pmd.sourceforge.net/pmd-4.3.0/rules/ junit.html#JUnitTestsShouldIncludeAssert • [ରࡦ] phpunit —report-useless-tests phpunit.de/manual/current/en/risky-tests.html • [ରࡦ] Test ͷଥੑΛݕূ͢Δ Mutation Test
2. ։ൃऀͷखݩ͚ͩͰಈ͘ def test_config_exists(): assert os.path.isfile(‘/Users/shoma/.gitconfig’)
2. ։ൃऀͷखݩ͚ͩͰಈ͘ • ιʔείʔυཧ֎ͷϑΝΠϧҙ • /usr/bin ͱ͔ո͍͠ • ڥηοτΞοϓͷқ্͕͕Δ •
127.0.0.1/localhost ҙ͕ඞཁ • [ରࡦ] ڥʹԠͯ͡มΘΔͷڥมΛ͏ • [ରࡦ] ηοτΞοϓؚΊ࣮ͨߦํ๏ͷ౷ҰԽ • [ରࡦ] ૣΊͷ CI • [ରࡦ] ։ൃ/ຊ൪Ұக 12factor.net/ja/dev-prod-parity
3. ςετ͍ͯ͠ΔͷMockͩ class TheService { public Long calculate(Long a, Long
b) { return innerService.calculate(a, b); } } @Test void testCalulate() { InnerService service = mock(InnerService.class): when(service.calculate(19L, 21L)).thenReturn(42L); // ུ Long res = theService.calculate(19L, 21L); assertEquals(LongValueOf(42L), res); }
3. ςετ͍ͯ͠ΔͷMockͩ • [ݪҼ] Mock Λ͍͗ͯ͢͠·͏ • [ରࡦ] CodeCoverageϨϙʔτΛΈΑ͏ •
[ରࡦ] Mutation Test (લड़)
4. ඪ४ػೳͷςετ • Bug͕͋ΔͳΒ͓͍ͬͯͯΑ͍ • ਖ਼نදݱͩͱΓ͕ͪ • ʮTDD ։ൃதͷෆ҆Λίϯτʔϧ͢Δํ๏ͩʯ •
ڍಈͷཧղਂ·Δ • [ݪҼ] ϥΠϒϥϦʹςετ͕ແ͔ͬͨ ˠ OSS ߩݙνϟϯε • [ରࡦ] ͋ͳͨͷίʔυΛςετ͠Α͏
5. ಈ͔͢ͱ՝ۚ͞ΕΔ • [ݪҼ] ΫϥυαʔϏεΛ͍ͬͯΔ • [ݪҼ] Credential ͷѻ͍͕͍͋͠… •
[ରࡦ] SDK ʹ Stub/Fake/Simulator ͕͋Δ͔ ֬ೝ͠Α͏ • [ରࡦ] ͜͜ Mock Խ
6. ͱ͖Ͳ͖ࣦഊ͢Δ • ΜͰ·͢ • [ରࡦ] Vefiry-Act-Vefiry • arrange લͷࣄલ͕݅Ήঢ়ଶͰ͋Δ͔֬ೝ͢Δ
testautomationpatterns.wikispaces.com/VERIFY-ACT-VERIFY • [ରࡦ] ෆ҆ఆͳςετΛmark ͓ͯ͘͠ github.com/nodejs/node/wiki/Flaky-tests • [ରࡦ] TestSize Λنఆͯ͠UnitTest ͱͯ͠ΔൣғΛܾΊΔ testing.googleblog.com/2010/12/test-sizes.html
Happy Unit Testing!