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
520
品質への取り組み
shomas
2
5.7k
メルカリにおける Software Engineer in Test
shomas
5
8.7k
Other Decks in Technology
See All in Technology
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
220
適材適所の技術選定 〜GraphQL・REST API・tRPC〜 / Optimal Technology Selection
kakehashi
1
170
BLADE: An Attempt to Automate Penetration Testing Using Autonomous AI Agents
bbrbbq
0
300
Can We Measure Developer Productivity?
ewolff
1
150
【令和最新版】AWS Direct Connectと愉快なGWたちのおさらい
minorun365
PRO
5
750
AGIについてChatGPTに聞いてみた
blueb
0
130
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
180
Why does continuous profiling matter to developers? #appdevelopercon
salaboy
0
190
dev 補講: プロダクトセキュリティ / Product security overview
wa6sn
1
2.3k
Amazon Personalizeのレコメンドシステム構築、実際何するの?〜大体10分で具体的なイメージをつかむ〜
kniino
1
100
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
130
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1030
460k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Teambox: Starting and Learning
jrom
133
8.8k
Into the Great Unknown - MozCon
thekraken
32
1.5k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Designing for Performance
lara
604
68k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Speed Design
sergeychernyshev
24
610
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
A Modern Web Designer's Workflow
chriscoyier
693
190k
A better future with KSS
kneath
238
17k
The Cost Of JavaScript in 2023
addyosmani
45
6.7k
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!