JUnit 5 Basics 14 - Asserting exceptions with assertThrows
HTML-код
- Опубликовано: 22 авг 2024
- Learn how to test methods that throw exceptions. Using `assertThrows`, you can make sure that methods not just throw exceptions, but also the right ones!
Source code available here: github.com/kou...
JUnit 5 Basics is an introduction to the JUnit Jupiter testing framework. JUnit is the defacto standard for testing in Java. learn about how to use JUnit to write effective tests. Understand the features of JUnit including the `@Test` annotation, assertion APIs, test lifecycle and controlling executions.
Thank you! This was a lot more helpful then the articles I found on this.
That's exactly what i was looking for 🙂
Thank you, brother !
thank you so much for this very clear explanation
The explanation is very helpful for me! Thanks)
Thank you !!! Very neatly explained
You are extremely good at explanations. And what a handsome guy you are!
This was incredibly helpful. Thank you so much!
Thank you for this.
This is fantastic, thank you!
Very helpful! Thank you.
Maybe a stupid question because I am lacking the knowledge, why do we need to pass a lambda and not the method itself?
assertThrows has the parameter signature, so it wont accept . Instead, lambdas will be 'Executable'.
@@gaurabdasgupta1239 Thank you! Ok, then I could also pass an object which inherits from the abstract class "Executable"?
@@gaurabdasgupta1239 u the real MVP
how do you check whats happening after an exception is thrown?
for example I have a method which can handle the exception (if thrown) and continues execution, so how do I check if the method is continuing its execution after the exception is thrown, in junits?
Really good thnx
great video ;)
It's not throwing the exception and the test fails
it will through an exception if you take 2nd paramter to be 0 and that test method will show green bar only if the exception is thrown.
That means you need to throw exception to make your bar green or pass your test.
Thanks alot 😊
Hi kirti have you completed this series?
Please make it for C#
I literally can’t find anything that explains how to do this in C#
I don't get why it is () -> m.divide(5, 0) instead of (x,y) -> m.divide(5, 0).
You don't need x,y since you aren't using them in divide method call.
In 7 min Im getting error Error:(19, 53) java: lambda expressions are not supported in -source 1.5
(use -source 8 or higher to enable lambda expressions). How to fix this?
change to java 8 version
Add this in your pom.xml or if already present with 1.7 then change it to 1.8
1.8
1.8
damn bravv yo good
Where can I see all the methods in JUnit5?
You can find the details in the JUnit 5 API JavaDoc
junit.org/junit5/docs/current/api/
Seems like you aren't a TDD enthusiast.