Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-1782

Junit3 Misusage

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 0.9.0.0
    • None

    Description

      This is found while I was working on KAFKA-1580: in many of our cases where we explicitly extend from junit3suite (e.g. ProducerFailureHandlingTest), we are actually misusing a bunch of features that only exist in Junit4, such as (expected=classOf). For example, the following code

      import org.scalatest.junit.JUnit3Suite
      import org.junit.Test
      
      import java.io.IOException
      
      class MiscTest extends JUnit3Suite {
        @Test (expected = classOf[IOException])
        def testSendOffset() {
        }
      }
      

      will actually pass even though IOException was not thrown since this annotation is not supported in Junit3. Whereas

      import org.junit._
      
      import java.io.IOException
      
      class MiscTest extends JUnit3Suite {
        @Test (expected = classOf[IOException])
        def testSendOffset() {
        }
      }
      

      or

      import org.scalatest.junit.JUnitSuite
      import org.junit._
      
      import java.io.IOException
      
      class MiscTest extends JUnit3Suite {
        @Test (expected = classOf[IOException])
        def testSendOffset() {
        }
      }
      

      or

      import org.junit._
      
      import java.io.IOException
      
      class MiscTest {
        @Test (expected = classOf[IOException])
        def testSendOffset() {
        }
      }
      

      will fail.

      I would propose to not rely on Junit annotations other than @Test itself but use scala unit test annotations instead, for example:

      import org.junit._
      
      import java.io.IOException
      
      class MiscTest {
        @Test
        def testSendOffset() {
          intercept[IOException] {
            //nothing
          }
        }
      }
      
      

      will fail with a clearer stacktrace.

      Attachments

        1. KAFKA-1782_2015-06-18_11:52:49.patch
          94 kB
          Alexander Pakulov
        2. KAFKA-1782_2015-07-15_16:57:44.patch
          113 kB
          Alexander Pakulov
        3. KAFKA-1782_2015-07-16_11:50:05.patch
          92 kB
          Alexander Pakulov
        4. KAFKA-1782_2015-07-16_11:56:11.patch
          92 kB
          Alexander Pakulov
        5. KAFKA-1782.patch
          92 kB
          Alexander Pakulov
        6. KAFKA-1782.patch
          183 kB
          Alexander Pakulov

        Issue Links

          Activity

            People

              apakulov Alexander Pakulov
              guozhang Guozhang Wang
              Guozhang Wang Guozhang Wang
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: