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.

Комментарии • 32

  • @Superkri99
    @Superkri99 3 года назад +9

    Thank you! This was a lot more helpful then the articles I found on this.

  • @landery39
    @landery39 2 года назад +1

    That's exactly what i was looking for 🙂

  • @marztianpapi3419
    @marztianpapi3419 2 месяца назад

    Thank you, brother !

  • @r.d.6536
    @r.d.6536 2 года назад

    thank you so much for this very clear explanation

  • @777MALexa
    @777MALexa 2 года назад

    The explanation is very helpful for me! Thanks)

  • @santhuk3318
    @santhuk3318 Год назад

    Thank you !!! Very neatly explained

  • @user-lv6pn5qx4n
    @user-lv6pn5qx4n 2 года назад

    You are extremely good at explanations. And what a handsome guy you are!

  • @Vyse86
    @Vyse86 2 года назад

    This was incredibly helpful. Thank you so much!

  • @JoaoLima-pq1hm
    @JoaoLima-pq1hm 9 месяцев назад

    Thank you for this.

  • @andoniaguirrearanguren9418
    @andoniaguirrearanguren9418 2 года назад

    This is fantastic, thank you!

  • @phillipblackwell7829
    @phillipblackwell7829 3 года назад

    Very helpful! Thank you.

  • @perschistence2651
    @perschistence2651 4 года назад +9

    Maybe a stupid question because I am lacking the knowledge, why do we need to pass a lambda and not the method itself?

    • @gaurabdasgupta1239
      @gaurabdasgupta1239 4 года назад +15

      assertThrows has the parameter signature, so it wont accept . Instead, lambdas will be 'Executable'.

    • @perschistence2651
      @perschistence2651 4 года назад +1

      @@gaurabdasgupta1239 Thank you! Ok, then I could also pass an object which inherits from the abstract class "Executable"?

    • @abhinavporwal4766
      @abhinavporwal4766 4 года назад

      @@gaurabdasgupta1239 u the real MVP

  • @sudhamshakula128
    @sudhamshakula128 Год назад +1

    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?

  • @tharinmahale9878
    @tharinmahale9878 3 года назад

    Really good thnx

  • @romandzhadan5546
    @romandzhadan5546 3 года назад

    great video ;)

  • @Maceta444
    @Maceta444 3 года назад +2

    It's not throwing the exception and the test fails

    • @shobhitsingh7735
      @shobhitsingh7735 3 года назад

      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.

  • @kirtisingh3234
    @kirtisingh3234 4 года назад

    Thanks alot 😊

  • @matthewbaier766
    @matthewbaier766 3 года назад

    Please make it for C#
    I literally can’t find anything that explains how to do this in C#

  • @MrKarannkaka
    @MrKarannkaka 3 года назад

    I don't get why it is () -> m.divide(5, 0) instead of (x,y) -> m.divide(5, 0).

    • @Chocolateboy-hx1fr
      @Chocolateboy-hx1fr Месяц назад

      You don't need x,y since you aren't using them in divide method call.

  • @peterlesko8644
    @peterlesko8644 4 года назад

    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?

    • @nikolapetrovic4415
      @nikolapetrovic4415 3 года назад

      change to java 8 version

    • @TheWorldlife83
      @TheWorldlife83 3 года назад

      Add this in your pom.xml or if already present with 1.7 then change it to 1.8
      1.8
      1.8

  • @Kwatch
    @Kwatch 4 года назад

    damn bravv yo good

  • @gonzalo2323
    @gonzalo2323 3 года назад

    Where can I see all the methods in JUnit5?

    • @prashantprakash7142
      @prashantprakash7142 3 года назад

      You can find the details in the JUnit 5 API JavaDoc
      junit.org/junit5/docs/current/api/

  • @drcl7429
    @drcl7429 2 года назад

    Seems like you aren't a TDD enthusiast.