Spring Framework
  1. Spring Framework
  2. SPR-5292

Add support for parameterized JUnit 4 tests in the Spring TestContext Framework

    Details

    • Last commented by a User:
      true

      Description

      SpringJUnit4ClassRunner is unaware of @Parameters annotation that normally is processed with JUnit's own Parameterized runner.

      1. ConstructorArgFromSpringConfigTestRunner.java
        4 kB
        Ruud Senden
      2. junit4_SpringParameterizedRunner.java
        6 kB
        Manjuka Soysa
      3. ParameterizedDirtiesContext.java
        5 kB
        Nikolay Blindov
      4. SpringJUnit4ParameterizedClassRunner.java
        22 kB
        Josef Eisl
      5. SpringJUnit4ParameterizedClassRunner.java.v2
        3 kB
        Ib
      6. SpringParameterizedRunner.java
        5 kB
        Jon Burgin

        Issue Links

          Activity

          Hide
          Ib added a comment -

          None of the presently attached junit runners worked for me for one reason or another. As such, I wrote a runner that met my needs. I thought others might benefit from it, hence my sharing it here - by me attaching a file named SpringJUnit4ParameterizedClassRunner.java.v2

          Show
          Ib added a comment - None of the presently attached junit runners worked for me for one reason or another. As such, I wrote a runner that met my needs. I thought others might benefit from it, hence my sharing it here - by me attaching a file named SpringJUnit4ParameterizedClassRunner.java.v2
          Hide
          Gaetan Pitteloud added a comment -

          I just submitted the pull request 277 for this issue, in the form of a single runner that is able to run both parameterized and non-parameterized tests in the TestContext framework. I developed it some times ago and have been using it since then without any issue. The runner does not contain the spring-profile feature Chris Beams is talking about, but only "raw" parameterized tests.

          Show
          Gaetan Pitteloud added a comment - I just submitted the pull request 277 for this issue, in the form of a single runner that is able to run both parameterized and non-parameterized tests in the TestContext framework. I developed it some times ago and have been using it since then without any issue. The runner does not contain the spring-profile feature Chris Beams is talking about, but only "raw" parameterized tests.
          Hide
          Ruud Senden added a comment -

          It is not exactly a solution for the described problem, but the attached ConstructorArgFromSpringConfigTestRunner.java takes a different approach for parameterizing a unit test. Test classes will need to define a single constructor taking a single parameter. The runner will then run the test class once for every Spring bean that matches the constructor parameter type.

          Please note that this class currently only performs dependency injection; for example it doesn't handle Spring Test annotations like ExpectedException, Repeat etc.

          Show
          Ruud Senden added a comment - It is not exactly a solution for the described problem, but the attached ConstructorArgFromSpringConfigTestRunner.java takes a different approach for parameterizing a unit test. Test classes will need to define a single constructor taking a single parameter. The runner will then run the test class once for every Spring bean that matches the constructor parameter type. Please note that this class currently only performs dependency injection; for example it doesn't handle Spring Test annotations like ExpectedException, Repeat etc.
          Hide
          Ruud Senden added a comment -

          Run test once for each Spring bean that matches the single test constructor parameter type.

          Show
          Ruud Senden added a comment - Run test once for each Spring bean that matches the single test constructor parameter type.
          Hide
          Nikolay Blindov added a comment -

          I have attached junit runner (a file namedParameterizedDirtiesContext.java) worked for me. My ruuner is inheritor of junit Parameterized ruuner and uses inheritor of SpringJUnit4ClassRunner for creation a test. So, the runner uses junit approach for parameterizing a unit test and support all SpringJUnit functionalites. The ruuner work with junit 4.8.2 and or higher version.

          Show
          Nikolay Blindov added a comment - I have attached junit runner (a file namedParameterizedDirtiesContext.java) worked for me. My ruuner is inheritor of junit Parameterized ruuner and uses inheritor of SpringJUnit4ClassRunner for creation a test. So, the runner uses junit approach for parameterizing a unit test and support all SpringJUnit functionalites. The ruuner work with junit 4.8.2 and or higher version.

            People

            • Assignee:
              Sam Brannen
              Reporter:
              Tuomas Kiviaho
              Last updater:
              Juergen Hoeller
            • Votes:
              30 Vote for this issue
              Watchers:
              37 Start watching this issue

              Dates

              • Created:
                Updated:
                Days since last comment:
                31 weeks, 6 days ago