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
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
54
Pkl/2024-04-17-llt31
ottijp
0
81
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
150
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
270
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
150
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
160
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
140
AWSインフラのデプロイをCDKでカイゼンする/2022-03-23-llt25
ottijp
0
86
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
100
Other Decks in Technology
See All in Technology
american aa airlines®️ USA Contact Numbers: Complete 2025 Support Guide
aaguide
0
500
Delta airlines Customer®️ USA Contact Numbers: Complete 2025 Support Guide
deltahelp
0
1.1k
【あのMCPって、どんな処理してるの?】 AWS CDKでの開発で便利なAWS MCP Servers特集
yoshimi0227
6
730
VS CodeとGitHub Copilotで爆速開発!アップデートの波に乗るおさらい会 / Rapid Development with VS Code and GitHub Copilot: Catch the Latest Wave
yamachu
2
340
Contributing to Rails? Start with the Gems You Already Use
yahonda
2
120
CDK Toolkit Libraryにおけるテストの考え方
smt7174
1
450
伴走から自律へ: 形式知へと導くSREイネーブリングによる プロダクトチームの信頼性オーナーシップ向上 / SRE NEXT 2025
visional_engineering_and_design
3
230
american airlines®️ USA Contact Numbers: Complete 2025 Support Guide
supportflight
1
120
データ基盤からデータベースまで?広がるユースケースのDatabricksについて教えるよ!
akuwano
3
160
NewSQLや分散データベースを支えるRaftの仕組み - 仕組みを理解して知る得意不得意
hacomono
PRO
3
230
United™️ Airlines®️ Customer®️ USA Contact Numbers: Complete 2025 Support Guide
flyunitedguide
0
780
インフラ寄りSREの生存戦略
sansantech
PRO
9
3.4k
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
40
1.9k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.8k
A designer walks into a library…
pauljervisheath
207
24k
How GitHub (no longer) Works
holman
314
140k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
740
Reflections from 52 weeks, 52 projects
jeffersonlam
351
21k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
107
19k
A Tale of Four Properties
chriscoyier
160
23k
4 Signs Your Business is Dying
shpigford
184
22k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.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