單元測試(Unit Testing)的程式碼測式覆蓋率(test coverage)的意思如下。
2021/6/2
2021/4/23
JUnit 測試方法中多個Assertions與assertAll()差別 multi-assertions-assertall-difference
JUnit單元測試有時在一個@Test測試方法中會需要用多個Assertions來驗證,例如回傳結果物件的所有屬性是否皆正確。而直接執行多個Assertions及使用JUnit 5才有的Assertions.assertAll()區別如下。
2020/12/22
Maven Surefire Plugin run Spring Boot JUnit test pass environment variables
Maven Surefire Plugin執行Spring Boot的JUnit測試傳入環境變數的方法如下。
2020/4/10
2019/8/31
JUnit 執行時出現錯誤 java.lang.NoClassDefFoundError
今天在Spring Boot + Gradle新的專案執行JUnit測試時,出現java.lang.NoClassDefFoundError的錯誤,過程及原因如下。
2019/5/10
2019/4/24
Spring Boot 2.x Unit Test測試RestController GET method
簡單記錄在Spring Boot 2.x對掛有@RestController的Controller的方法以JUnit 5進行單元測試。
2019/2/16
Spring Boot 2 JUnit 4 to JUnit 5 @MockBean 無法注入
今天工作的Spring Boot專案將原來的JUnit 4升至JUnit 5時,原本測試程式中使用@MockBean注入的mock物件變成無法注入,執行時為null導致NullPointerException錯誤。
2019/1/10
2018/12/4
Eclipse 寫一支簡單的程式及JUnit測試程式並執行覆蓋率測試
本篇主要是要介紹怎麼使用Eclipse的程式覆蓋率測試工具(EclEmma Code Coverage plugin)。通常會要寫測試程式的工作就會要求測試程式的覆蓋率。
2018/8/15
2018/3/5
JUnit @BeforeClass, @Before, @Test, @After, @AfterClass 執行順序
JUnit 4的@BeforeClass, @Before, @Test, @After, @AfterClass執行順序如下。
2018/3/4
JUnit 使用Test Suite來包裝多個Test Case
JUnit的Suite可用來組織你要執行的Test Case,例如有三個要被測試的類別分別為TestCaseA,TestCaseB,TestCaseC,若要一次執行這三個Test Case,可利用Suite類別來達成。
什麼是單元測試(Unit Test)
單元測試(Unit Test)用來檢查一個獨立工作單位的行為,在Java應用程式中這個獨立的工作單位通常是一個方法(Method)。單元測試用來確認一個方法在接收特定的輸入後是否會得到預期的輸出。相對於單元測試,整合測試(Integration Test)是指檢查數個元件之間的互動。
2018/3/3
2018/2/20
JUnit 4 assertEquals 比較兩個double值
JUnit 4 要比較兩個double值可使用assertEquals(double expected, double actual, double delta)。