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
ミューテーション解析について調べた/2019-02-26-llt7
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Satoshi SAKAO
February 26, 2019
Technology
0
260
ミューテーション解析について調べた/2019-02-26-llt7
社内のLTイベント「えるLT Vol.7」で発表した資料です
Satoshi SAKAO
February 26, 2019
Tweet
Share
More Decks by Satoshi SAKAO
See All by Satoshi SAKAO
Testcontainers/2024-11-20-llt32
ottijp
0
77
Pkl/2024-04-17-llt31
ottijp
0
110
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
180
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
300
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
180
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
200
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
170
AWSインフラのデプロイをCDKでカイゼンする/2022-03-23-llt25
ottijp
0
110
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
120
Other Decks in Technology
See All in Technology
StrandsとNeptuneを使ってナレッジグラフを構築する
yakumo
1
120
Bill One 開発エンジニア 紹介資料
sansan33
PRO
5
17k
FinTech SREのAWSサービス活用/Leveraging AWS Services in FinTech SRE
maaaato
0
130
顧客の言葉を、そのまま信じない勇気
yamatai1212
1
360
今日から始めるAmazon Bedrock AgentCore
har1101
4
410
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
10k
Digitization部 紹介資料
sansan33
PRO
1
6.8k
顧客との商談議事録をみんなで読んで顧客解像度を上げよう
shibayu36
0
250
Context Engineeringの取り組み
nutslove
0
360
ファインディの横断SREがTakumi byGMOと取り組む、セキュリティと開発スピードの両立
rvirus0817
1
1.4k
AIと新時代を切り拓く。これからのSREとメルカリIBISの挑戦
0gm
0
2.3k
ブロックテーマ、WordPress でウェブサイトをつくるということ / 2026.02.07 Gifu WordPress Meetup
torounit
0
190
Featured
See All Featured
sira's awesome portfolio website redesign presentation
elsirapls
0
150
We Have a Design System, Now What?
morganepeng
54
8k
Believing is Seeing
oripsolob
1
56
Evolving SEO for Evolving Search Engines
ryanjones
0
130
エンジニアに許された特別な時間の終わり
watany
106
230k
We Are The Robots
honzajavorek
0
160
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
220
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
380
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
430
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
120
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.9k
Transcript
ミューテーション解析について調べた Satoshi SAKAO えるLT Vol.7 2019/02/26 (Tue) N1
話すひと N2 インフォコム株式会社 オープンイノベーションセンター # アプリケーションエンジニア JS (ES6) / Node.js
/ GCP / IoT / iOS (Swift) エースコンバット7 / 技術士合格に向けた学習 Satoshi SAKAO @ottijp
N3 ミューテーション解析?
ミューテーション解析とは • = ミューテーションテスト • テストの十分さを測定する手法 • 欠陥を含むプログラムを生成(ミューテーション操作)し, それを検出できるかどうかで,テストの欠陥検出能力を測る •
さらなるテストケース作成の必要性などの評価に利用できる N4
図解 N5 https://codezine.jp/article/detail/10066
具体例 N6 // monthが0〜11ならtrueを返す function isValid(month) { return month >=
0 && month <= 11 } return month < 0 && month <= 11 return month >= 0 && month > 11 ミューテーション操作 ミュータント ミュータント
具体例 N7 return month >= 0 && month <= 11
return month < 0 && month <= 11 return month >= 0 && month > 11 望ましいテスト結果 テストの失敗が期待される
Swiftでやってみる N8 https://github.com/SeanROlszewski/muter
Swiftでやってみる N9 class MonthValidator { /// monthが0〜11であればtrueを返す func isValid(_ month:
Int) -> Bool { return month >= 0 && month <= 11 } } // more Swifty return 0...11 ~= month
Swiftでやってみる N10 final class swift_muterTests: XCTestCase { func testMonthValidator_valid() {
XCTAssertEqual(MonthValidator().isValid(11), true) } func testMonthValidator_inValid() { XCTAssertEqual(MonthValidator().isValid(-1), false) } } 11 TRUE -1 FALSE
Swiftでやってみる N11 $ muter -------------------------- Applied Mutation Operators -------------------------- File
Position Applied Mutation Operator Mutation Test Result ---- -------- ------------------------- -------------------- swift_muter.swift Line: 4, Column: 18 Negate Conditionals passed swift_muter.swift Line: 4, Column: 32 Negate Conditionals failed -------------------- Mutation Test Scores -------------------- Mutation Score of Test Suite (higher is better): 50/100 File # of Applied Mutation Operators Mutation Score ---- ------------------------------- -------------- swift_muter.swift 2 50 ん?
Swiftでやってみる N12 return month >= 0 && month >= 11
2つめのミュータント 11 TRUE -1 FALSE ミュータントの欠陥を検出できない
Swiftでやってみる N13 func testMonthValidator_inValid_over11() { XCTAssertEqual(MonthValidator().isValid(12), false) } テストを追加 11
TRUE -1 FALSE 12 FALSE 欠陥を検出できるようになった
Swiftでやってみる N14 $ muter -------------------------- Applied Mutation Operators -------------------------- File
Position Applied Mutation Operator Mutation Test Result ---- -------- ------------------------- -------------------- swift_muter.swift Line: 4, Column: 18 Negate Conditionals passed swift_muter.swift Line: 4, Column: 32 Negate Conditionals passed -------------------- Mutation Test Scores -------------------- Mutation Score of Test Suite (higher is better): 100/100 File # of Applied Mutation Operators Mutation Score ---- ------------------------------- -------------- swift_muter.swift 2 100 OK
課題:等価ミュータント • 元のプログラムと常に同じように振る舞うミュータント (等価ミュータント)が発生しうる • このミュータントをkillするようなテストケースの生成は不可能 • ミューテーション解析を実用に移すことを阻む大きな障害の一つ N15
まとめ • ミューテーション解析で,テストの欠陥検出能力を測定できる • テストの十分さを評価する指標として活用できる • 実用には等価ミュータントに注意 N16
$ exit N17
N18 Appendix
留意点 • muterはプロジェクトディレクトリのキャッシュが悪さしがちなので注意 • Muter sometimes fails on Swift PM
projects, probably due to module cache problems · Issue #72 · SeanROlszewski/muter • https://github.com/SeanROlszewski/muter/issues/72 • swift package clean できれいにしてあげると通る • muterはまだ比較演算子のミューテーションしか対応していない • LLVMレベルのミューテーション解析ライブラリもあったが試していない N19
等価ミュータントの例 N20 func isEven(_ n: Int) -> Bool { return
n % 2 == 0 } ミュータント return -n % 2 == 0 ミュータントをkillするテストは書けない
refs • ミューテーション解析 - Wikipedia • https://ja.wikipedia.org/ミューテーション解析 • ミューテーションテストに触れてみよう |
ギャップロ • https://www.gaprot.jp/pickup/tips/mutation-testing • ソフトウェアのテスト品質を効果的に測定するミューテーション 解析 (1/3):CodeZine(コードジン) • https://codezine.jp/article/detail/10066 N21