SlideShare a Scribd company logo
1 of 24
Download to read offline
JUnit入門
Yutaka Kinjo
JUnit
A programmer-oriented
testing framework for Java
Standard Method
assertThat(actual, is(expected));
Standard Method
assertThat(actual, is(expected));
実際の値 期待値
assertThat(actual, is(expected));
実際の値 期待値
ex.加算用のメソッドをテストする時
1 + 2 = 3 の場合、3を期待値とすると
Standard Method
Add Method Test
@Test
public void addで1と2の加算結果が返却される() {
!
int a = 1;
int b = 2;
int expected = 3;
Calc sut = new Calc();
int actual = sut.add(a,b);
!
assertThat(actual ,is(expected));
テスト結果 Green or Red
Test result
テスト成功
テスト失敗
Test result
テスト失敗
Expected: is <3>
but: was <-1>
Add Method
public int add(int a, int b) {
return a - b;
}
public int add(int a, int b) {
return a + b;
}
テスト結果 Green
Routine
テスト 修正
一度書けば何度でもテスト可能
Routine
テスト 修正
テストの実行は軽量(対象のメソッドだけ)
高速なデバックが可能になる!!
What is Matcher ?
Standard Method
assertThat(actual, is(expected));
Matcher
actual is expected が真なら Green
Matcher Method
is
not
nullValue
notNullValue
sameInstance
instanceOf
Matcher Method
assertThat(actual, is(expected));
assertThat(actual, not(expected));
: actual と expected が同じ値なら Greenis
not : actual と expected が違う値なら Green
Matcher Method
assertThat(actual, nullValue());
assertThat(actual, notNullValue());
: actual が null なら GreennullValue
notNullValue : actual が null でないなら Green
Matcher Method
assertThat(actual,sameInstance(expected));
assertThat(actual,instanceOf(expected));
: actual と expected が
同じインスタンスなら Green
sameInstance
instanceOf : actual が expected で
指定したインスタンスなら Green
What is Annotation ?
Annotation
日本語だと「注釈」
Annotation
@Test
public void addで1と2の加算結果が返却される() {
!
int a = 1;
int b = 2;
int expected = 3;
Calc sut = new Calc();
int actual = sut.add(a,b);
!
assertThat(actual ,is(expected));
Test 対象のメソッドを示す
Annotation
@Test
@Before
@After
@BeforeClass
@AfterClass
@Ignore
Annotation
@Test : テスト対象を示す
@Before : テストメソッドの前に毎回実行される
@After : テストの後に毎回実行される
@BeforeClass : テストクラスの前に実行される
@AfterClass : テストクラスの後に実行される
@Ignore : テスト対象でないことを示す
JUnit入門 Key word
assertThat
matcher
annotation
TDD
What is TDD ?
http://www.slideshare.net/t_wada/
devlove2012-twada-tdd

More Related Content

More from Yutaka Kinjyo

ちょっと怖くなくったRails
ちょっと怖くなくったRailsちょっと怖くなくったRails
ちょっと怖くなくったRailsYutaka Kinjyo
 
コンテキストと文化
コンテキストと文化コンテキストと文化
コンテキストと文化Yutaka Kinjyo
 
開発チームのためのコミュニケーションとコンテキストの作り方
開発チームのためのコミュニケーションとコンテキストの作り方開発チームのためのコミュニケーションとコンテキストの作り方
開発チームのためのコミュニケーションとコンテキストの作り方Yutaka Kinjyo
 

More from Yutaka Kinjyo (9)

一度死んだ話
一度死んだ話一度死んだ話
一度死んだ話
 
Deepsmarts
DeepsmartsDeepsmarts
Deepsmarts
 
The dankai
The dankaiThe dankai
The dankai
 
IeLt2014
IeLt2014IeLt2014
IeLt2014
 
ちょっと怖くなくったRails
ちょっと怖くなくったRailsちょっと怖くなくったRails
ちょっと怖くなくったRails
 
怖いRails
怖いRails怖いRails
怖いRails
 
コンテキストと文化
コンテキストと文化コンテキストと文化
コンテキストと文化
 
開発チームのためのコミュニケーションとコンテキストの作り方
開発チームのためのコミュニケーションとコンテキストの作り方開発チームのためのコミュニケーションとコンテキストの作り方
開発チームのためのコミュニケーションとコンテキストの作り方
 
Ie lt
Ie ltIe lt
Ie lt
 

Recently uploaded

【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Danieldanielhu54
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 

Recently uploaded (10)

【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Daniel
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 

Junit intro