java - Testing for optional exception in parameterized JUnit 4+ test -


I am trying to write a unit test for a method that takes a string as a parameter and a Exceptions are distorted (and if it's okay then none). I want to write a parametred test that feeds in many strings and expected exceptions (in which none is thrown when input string is created well!). If @Test (expect = SomeException.class) is trying to use annotations, then I have two problems:

  1. Expected = Null is not allowed, so I How can I test for the expected outcome of an exception (for well-formed input wires)?

  2. Expected = Not possible? I have not tried this yet, but I have a strong doubt that this is the case after reading (Can you please tell that this is true?): This is the best solution I have found so far. What do you think about it, especially than that:

    Thanks for any help, I look forward to discussion :) <

    • ValidStringsTest
    • InvalidStringsTest

      / Li>

      Remember: Readability of your tests is even more important:

      Note: Already examines all valid assumptions (not an exception throwing). Do not use unique flags, terms and logic within JUnit test cases from the readability of the production code. The simplicity is the king.

      Also see my answer for a hint that how to properly test for exceptions.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -