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
61
Pkl/2024-04-17-llt31
ottijp
0
89
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
160
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
280
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
160
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
170
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
150
AWSインフラのデプロイをCDKでカイゼンする/2022-03-23-llt25
ottijp
0
92
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
110
Other Decks in Technology
See All in Technology
Codeful Serverless / 一人運用でもやり抜く力
_kensh
7
440
未経験者・初心者に贈る!40分でわかるAndroidアプリ開発の今と大事なポイント
operando
5
680
はじめてのOSS開発からみえたGo言語の強み
shibukazu
1
590
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
8.8k
Unlocking the Power of AI Agents with LINE Bot MCP Server
linedevth
0
100
なぜスクラムはこうなったのか?歴史が教えてくれたこと/Shall we explore the roots of Scrum
sanogemaru
5
1.6k
RSCの時代にReactとフレームワークの境界を探る
uhyo
10
3.5k
ブロックテーマ時代における、テーマの CSS について考える Toro_Unit / 2025.09.13 @ Shinshu WordPress Meetup
torounit
0
130
AI開発ツールCreateがAnythingになったよ
tendasato
0
130
slog.Handlerのよくある実装ミス
sakiengineer
4
270
DevIO2025_継続的なサービス開発のための技術的意思決定のポイント / how-to-tech-decision-makaing-devio2025
nologyance
1
400
react-callを使ってダイヤログをいろんなとこで再利用しよう!
shinaps
1
250
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
9
580
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
139
34k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.6k
GraphQLの誤解/rethinking-graphql
sonatard
72
11k
Java REST API Framework Comparison - PWX 2021
mraible
33
8.8k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Speed Design
sergeychernyshev
32
1.1k
The Art of Programming - Codeland 2020
erikaheidi
56
13k
[RailsConf 2023] Rails as a piece of cake
palkan
57
5.8k
How to Think Like a Performance Engineer
csswizardry
26
1.9k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
36
2.5k
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