Uploaded image for project: 'WildFly Core'
  1. WildFly Core
  2. WFCORE-5655

Test preparation errors shall cause failure

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Minor
    • 18.0.0.Beta3, 18.0.0.Final
    • 18.0.0.Beta2
    • None
    • None

    Description

      Only one method invocation is expected when testing exceptions. Refers to [RSPEC-5783|https://rules.sonarsource.com/java/RSPEC-5783, RSPEC-5778

      Sample:

         public void testBad() throws Throwable {
              try {
                  // Test preparation - no Exception expected
                  // Test run - Exception expected
                  fail("Should not have been rechead");
              } catch (AssertionError ae) {
                  throw ae; // In worst case, this is missing - Test never fails.
              } catch (Throwable t) {
                  // Expected, test success. Broken test preparation is ignored, too.
              } finally {
                  // Clean up here
              }
          }
      
          public void testRefactored() throws Throwable {
              Throwable expected = null;
              try {
                  // Test preparation - no Exception expected
                  try {
                      // Test run - Exception expected
                  } catch (Throwable ex) {
                      expected = ex;
                  }
              } catch (Throwable t) {
                 // optional cleanup
                  throw t;  // Test preparation failed
              } finally {
                  // Clean up here
              }
              assertNotNull("Exception was expected, not succes", expected);
          }
      

      Attachments

        Activity

          People

            xf01213 Boris Unckel (Inactive)
            xf01213 Boris Unckel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: