SlideShare una empresa de Scribd logo
1 de 24
Descargar para leer sin conexión
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

Más contenido relacionado

Más de 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
 

Último

Último (12)

論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
 
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 

Junit intro