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
Migrating to JUnit 5
Search
LINE Developers Taiwan
PRO
October 21, 2020
Technology
3.7k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Migrating to JUnit 5
by Joanna Hu at TWJUG 20201021
https://twjug.kktix.cc/events/twjug202010
LINE Developers Taiwan
PRO
October 21, 2020
More Decks by LINE Developers Taiwan
See All by LINE Developers Taiwan
台大資管營企業參訪-Bowen Chen
line_developers_tw
PRO
0
59
2026TECHFRESH畢業分享會 - AI 時代的人生存檔點
line_developers_tw
PRO
0
2.8k
2026TECHFRESH畢業分享會 - 原生還是跨平台? App 開發踩坑實錄
line_developers_tw
PRO
0
2.8k
2026TECHFRESH畢業分享會 - 葬送的通靈師:化系統與用戶雜訊成行動訊號
line_developers_tw
PRO
0
2.8k
2026 TECHFRESH 畢業分享會 - AI-Native 重塑軟體工程與虛擬講師
line_developers_tw
PRO
0
2.8k
2026 TECHFRESH 畢業分享會 - 開發日常大解密!從領域驅動到企業級上線
line_developers_tw
PRO
0
2.8k
2026TECHFRESH畢業分享會 - Lightning Talk - E起 See See : 電商推薦讀心術? 數據說了算
line_developers_tw
PRO
0
2.8k
2026TECHFRESH畢業分享會 - Lightning Talk - 資料也要 CI/CD? 用 Airbyte 自動化資料同步
line_developers_tw
PRO
0
2.8k
2026TECHFRESH畢業分享會 - Lightning Talk - 打造精準高效的 MCP 設計模式與測試實務
line_developers_tw
PRO
0
2.8k
Other Decks in Technology
See All in Technology
AIツールを導入しても生産性はあがらない? カオナビが直面した 3つの壁と乗り越え方。/ Overcoming 3 Barriers to AI-Driven Productivity at kaonavi
kaonavi
0
460
オートマトンと字句解析でRoslynを読む
tomokusaba
0
130
AI研修(Day1)【MIXI 26新卒技術研修】
mixi_engineers
PRO
2
2.8k
NetBoxを利用した作業効率化の試み_NetDevNight4
tnoha
0
380
脱Jenkins、インターン生が挑んだCIツールGitHubActions移行
mixi_engineers
PRO
1
270
データベース研修【MIXI 26新卒技術研修】
mixi_engineers
PRO
1
700
AIQAのナレッジ構築について
qatonchan
1
130
ここは地獄!つらい朝会を体験することで、チームとしてのより良い振る舞いに気づくワークショップ / The stand-up meeting from hell in the game industry
scrummasudar
0
440
plamo-3-translateの開発
pfn
PRO
0
200
QA・ソフトウェアテスト研修【MIXI 26新卒技術研修】
mixi_engineers
PRO
3
1.8k
データエンジニアこそ組織のオントロジーに向き合うべき — 問いに答えるAIから、事業を動かすAIへ
gappy50
5
2.5k
もう一度考える SRE チームの作り方・育て方 / Rethinking SRE #1: Building and Growing SRE Teams
rrreeeyyy
1
140
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
200
New Earth Scene 8
popppiees
3
2.4k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
Accessibility Awareness
sabderemane
1
170
Agile that works and the tools we love
rasmusluckow
331
22k
How STYLIGHT went responsive
nonsquared
100
6.2k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
400
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
600
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
380
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
520
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Transcript
0LJUDWLQJWR -8QLW -RDQQD+X
About the Speaker Joanna Hu • Backend Engineer • Working
in LINE Taiwan since 2019
01 02 03 Summary :KDWLV-8QLW :K\PLJUDWLQJWR-8QLW +RZWRPLJUDWHWR-8QLW
:KDWLV-8QLW • -8QLW-XSLWHUWKHQHZSURJUDPPLQJH[WHQVLRQPRGHOIRUZULWLQJWHVWVDQGH[WHQVLRQVLQ-8QLW • -8QLW9LQWDJH 7HVW(QJLQH IRUUXQQLQJ-8QLWDQG-8QLWEDVHGWHVWVRQWKHSODWIRUP • -8QLW3ODWIRUP IRXQGDWLRQIRUODXQFKLQJWHVWLQJIUDPHZRUNVRQWKH-90
※Source from︓https://dzone.com/articles/7-reasons-to-consider-junit-5
:K\PLJUDWLQJWR-8QLW • 6XSSRUWHGLQPDMRU,'(%XLOGWRROV • ,QWHOOLM ,'($(FOLSVH96&RGH • 0DYHQ*UDGOH • (DV\PLJUDWLRQ
• -8QLWWHVWVFDQFRH[LVWZLWK-8QLWWHVWV • :HFDQXVHERWK-8QLW$VVHUW- DVVHUWLRQVLQRQHWHVW • 1HZ)HDWXUHV
-8QLW1HZ)HDWXUHV • 1HVWHGWHVWV • 'LVSOD\QDPH • 3DUDPHWHUL]HGWHVWV • 0XOWLSOH5XQQHUV •
%HWWHU$VVHUWLRQV EXWZHUHFRPPHQG$VVHUW- LQVWHDG
1HVWHGWHVWV • #1HVWHGFDQKDYHPXOWLSOHOHYHOV • 6XSSRUWQRQVWDWLFLQQHUFODVV class TestingAStackDemo { Stack<Object> stack;
@Test void isInstantiatedWithNew() { new Stack<>(); } @Nested class WhenNew { @BeforeEach void createNewStack() { stack = new Stack<>(); } @Test void isEmpty() { assertTrue(stack.isEmpty()); } @Test void throwsExceptionWhenPopped() { assertThrows(EmptyStackException.class, stack::pop); } @Nested class AfterPushing { // more tests... } } }
1HVWHGWHVWV
'LVSOD\QDPHV • $GG#'LVSOD\1DPH DQQRWDWLRQ • 6XSSRUWDGGLQJRQFODVVPHWKRG @DisplayName("A stack") class TestingAStackDemo
{ Stack<Object> stack; @Test @DisplayName("is instantiated with new Stack()") void isInstantiatedWithNew() { new Stack<>(); } @Nested @DisplayName("when new") class WhenNew { @BeforeEach void createNewStack() { stack = new Stack<>(); } @Test @DisplayName("is empty") void isEmpty() { assertTrue(stack.isEmpty()); } @Nested @DisplayName("after pushing an element") class AfterPushing { // more tests... } } }
'LVSOD\QDPHV • $GG#'LVSOD\1DPH DQQRWDWLRQ • 6XSSRUWDGGLQJRQFODVVPHWKRG
3DUDPHWHUL]HGWHVWV -8QLW class CalculatorJUnit5Test { @ParameterizedTest @ValueSource(strings = { "",
" ", " " }) void isBlank_ShouldReturnTrueForBlankStrings(String input) { assertThat(StringUtils.isBlank(input)).isTrue(); } @ParameterizedTest @NullSource void isBlank_ShouldReturnTrueForNullStrings(String input) { assertThat(StringUtils.isBlank(input)).isTrue(); } @ParameterizedTest @CsvSource({ "0,0,0", "1,1,2" }) void add(int first, int second, int expected) { final Calculator calculator = new Calculator(); final int result = calculator.add(first, second); assertThat(result).isEqualTo(expected); } }
0XOWLSOH5XQQHUV -8QLWRQO\VXSSRUWVVLQJOHUXQQHUZKLOH-8QLWVXSSRUWVPXOWLSOHH[WHQVLRQV // JUnit 4 @RunWith(MockitoJUnitRunner.class) public class CMSProductServiceTest {
// ... } // JUnit 5 @ExtendWith({ MockitoExtension.class, SoftAssertionsExtension.class }) public class CMSProductServiceTest { // ... }
+RZWRPLJUDWHWR-8QLW • 8SJUDGHWR-8QLWLQ0DYHQ*UDGOH • 8SJUDGH0DYHQWR 2U0DYHQVXUHILUHIDLOVDIHSOXJLQWR • 8SJUDGH*UDGOHWR • :ULWHQHZWHVWVLQ-8QLW
• 0LJUDWHH[LVWLQJ-8QLWWHVWV • 5HZULWH-8QLW5XOHWR-8QLW([WHQVLRQ LIDQ\
0LJUDWHH[LVWLQJ-8QLWWHVWV JUnit 4 JUnit 5 org.junit.Test org.junit.jupiter.api.Test org.junit.Before org.junit.jupiter.api.BeforeEach org.junit.After
org.junit.jupiter.api.AfterEach org.junit.BeforeClass org.junit.jupiter.api.BeforeAll org.junit.AfterClass org.junit.jupiter.api.AfterAll org.junit.Ignore org.junit.jupiter.api.Disabled org.junit.Assert org.junit.jupiter.api.Assertions (we use AssertJ) org.junit.Assert.assertThat org.hamcrest.MatcherAssert.assertThat org.junit.runner.RunWith org.junit.jupiter.api.extension.ExtendWith org.mockito.junit.MockitoJUnitRunner org.mockito.junit.jupiter.MockitoExtension org.springframework.test.context.junit4.SpringRu nner org.springframework.test.context.junit.jupiter.Spri ngExtension
5HZULWH-8QLW5XOHWR-8QLW([WHQVLRQ -8QLW5XOH public class EmbeddedMySqlRule extends ExternalResource { private EmbeddedMysql
embeddedMysql; @Override protected void before() { // ... embeddedMysql = EmbeddedMysql.anEmbeddedMysql(config, downloadConfig) .addSchema("ecac", ScriptResolver.classPathScript("db/setup.sql")) .start(); } @Override protected void after() { if (embeddedMysql != null) { embeddedMysql.stop(); } } }
5HZULWH-8QLW5XOHWR-8QLW([WHQVLRQ -8QLW([WHQVLRQ public class EmbeddedMySqlExtension implements AfterAllCallback, BeforeAllCallback { private
EmbeddedMysql embeddedMysql; @Override public void beforeAll(ExtensionContext extensionContext) throws Exception { // ... embeddedMysql = EmbeddedMysql.anEmbeddedMysql(config, downloadConfig) .addSchema("ecac", ScriptResolver.classPathScript("db/setup.sql")) .start(); } @Override public void afterAll(ExtensionContext extensionContext) throws Exception { if (embeddedMysql != null) { embeddedMysql.stop(); } } }
0LJUDWH8VLQJ,QWHOOL-,'($ 0LJUDWHRQHWHVW 0LJUDWHDOOWHVWV 5HIDFWRU!0LJUDWH https://blog.jetbrains.com/idea/2020/08/migrating-from-junit-4-to-junit-5/
• -8QLWZHEVLWHhttps://junit.org/junit5/ • 5HDVRQVWR&RQVLGHU-8QLWhttps://dzone.com/articles/7-reasons-to-consider-junit-5 • 0LJUDWLQJIURP-8QLWWR-8QLWhttps://blog.jetbrains.com/idea/2020/08/migrating-from-junit-4-to-junit-5/ 5HIHUHQFHV
THANK YOU