Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
70
Pkl/2024-04-17-llt31
ottijp
0
97
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
170
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
300
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
170
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
180
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
160
AWSインフラのデプロイをCDKでカイゼンする/2022-03-23-llt25
ottijp
0
100
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
110
Other Decks in Technology
See All in Technology
RAG/Agent開発のアップデートまとめ
taka0709
0
170
AWS Trainium3 をちょっと身近に感じたい
bigmuramura
1
140
re:Invent 2025 ふりかえり 生成AI版
takaakikakei
1
200
生成AI活用の型ハンズオン〜顧客課題起点で設計する7つのステップ
yushin_n
0
140
Debugging Edge AI on Zephyr and Lessons Learned
iotengineer22
0
180
Reinforcement Fine-tuning 基礎〜実践まで
ch6noota
0
180
Snowflakeでデータ基盤を もう一度作り直すなら / rebuilding-data-platform-with-snowflake
pei0804
4
1.4k
Haskell を武器にして挑む競技プログラミング ─ 操作的思考から意味モデル思考へ
naoya
6
1.5k
mairuでつくるクレデンシャルレス開発環境 / Credential-less development environment using Mailru
mirakui
1
160
形式手法特論:CEGAR を用いたモデル検査の状態空間削減 #kernelvm / Kernel VM Study Hokuriku Part 8
ytaka23
2
460
Sansanが実践する Platform EngineeringとSREの協創
sansantech
PRO
2
830
チーリンについて
hirotomotaguchi
6
1.9k
Featured
See All Featured
Thoughts on Productivity
jonyablonski
73
5k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.2k
The Language of Interfaces
destraynor
162
25k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
710
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
RailsConf 2023
tenderlove
30
1.3k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
390
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
36
6.2k
Being A Developer After 40
akosma
91
590k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Side Projects
sachag
455
43k
What's in a price? How to price your products and services
michaelherold
246
13k
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