课程: Complete Guide To Java Testing with JUnit 5 & Mockito
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Testing exceptions in JUnit 5
课程: Complete Guide To Java Testing with JUnit 5 & Mockito
Testing exceptions in JUnit 5
- [Instructor] When testing your code, it's important to consider what happens when your code is faced with unexpected situations. Whether that's invalid inputs or system failures, your application should gracefully handle these, providing meaningful feedback to users or logging necessary information for debugging. JUnit 5 provides a powerful mechanism to verify whether your code throws expected exceptions during testing. This enables you to validate the behavior of exception handling logic. Let's take a look at the calculator class again. Here, if the divisor is zero, we should test that the illegal argument exception is thrown. Currently in our test, we catch the exception and verify the result has not been set. We can make this test a little more robust by leveraging the assert throws method to directly assert that the exception is thrown. This will not only simplify the code, but also provide clear feedback in case of a failure. Let's refactor our test to utilize assert throws. By…
内容
-
-
-
-
Set up JUnit 5 in your Java application2 分钟 24 秒
-
(已锁定)
Write and run your first JUnit 5 test4 分钟 11 秒
-
(已锁定)
Assertions in JUnit 57 分钟 56 秒
-
(已锁定)
JUnit 5 test lifecycle1 分钟 51 秒
-
(已锁定)
JUnit 5 lifecycle hooks2 分钟 49 秒
-
(已锁定)
Testing exceptions in JUnit 52 分钟 54 秒
-
(已锁定)
Debug tests in JUnit 54 分钟 30 秒
-
(已锁定)
Best practices for writing tests in JUnit 52 分钟 17 秒
-
(已锁定)
Challenge: Write a JUnit 5 test for a temperature converter47 秒
-
(已锁定)
Solution: Write a JUnit 5 Test for a Temperature Converter6 分钟 33 秒
-
-
-
-
-
-
-
-