Uploaded image for project: '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
          rsenden 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
          rsenden 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
          rsenden Ruud Senden added a comment -

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

          Show
          rsenden Ruud Senden added a comment - Run test once for each Spring bean that matches the single test constructor parameter type.
          Hide
          nikolayb 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
          nikolayb 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.
          Hide
          mbjelac Marko Bjelac added a comment -

          I tried several runners attached here, but confirm that only SpringJUnit4ParameterizedClassRunner.java.v2 works for me.

          Show
          mbjelac Marko Bjelac added a comment - I tried several runners attached here, but confirm that only SpringJUnit4ParameterizedClassRunner.java.v2 works for me.
          Hide
          koen_serry Koen Serry added a comment -

          Since a pull request is created (and is confirmed to work), is there any reason not to merge it?

          Show
          koen_serry Koen Serry added a comment - Since a pull request is created (and is confirmed to work), is there any reason not to merge it?

            People

            • Assignee:
              sbrannen Sam Brannen
              Reporter:
              tuomas_kiviaho Tuomas Kiviaho
              Last updater:
              Koen Serry
            • Votes:
              40 Vote for this issue
              Watchers:
              45 Start watching this issue

              Dates

              • Created:
                Updated:
                Days since last comment:
                24 weeks, 5 days ago