Grails
  1. Grails
  2. GRAILS-6352

Support alternate JUnit4 test runners such as Theories

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.3.1
    • Fix Version/s: 2.3-RC1
    • Component/s: Testing
    • Labels:
      None

      Description

      See example test here: http://github.com/robfletcher/grails-springcache/blob/master/test/unit/grails/plugin/springcache/CacheKeyTests.groovy#L40

      The @Theory annotated test is simply ignored (presumably because the @RunWith annotation on the class is).

      Using @RunWith(Paramaterized) is even more problematic as it requires the test to have constructor arguments which the Grails runner does not allow.

        Issue Links

          Activity

          Hide
          Brian Atkinson added a comment -

          A non-passive way to achieve this might be to make use of @Rules. From what you list above it seems that a lot of the magic needs to be run once per test - i.e. setup transaction context before, then roll it back on finish. Something like this could also be accomplished though a rule. See org.junit.rules.TestWatchman as a class that might provide the right @Rule hooks to wrap the test with. Since rules wrap the test stack, they are the perfect place to inject such logic. It might even be possible to inject the rule into the test code at compile time making the change possibly passive.

          Show
          Brian Atkinson added a comment - A non-passive way to achieve this might be to make use of @Rules. From what you list above it seems that a lot of the magic needs to be run once per test - i.e. setup transaction context before, then roll it back on finish. Something like this could also be accomplished though a rule. See org.junit.rules.TestWatchman as a class that might provide the right @Rule hooks to wrap the test with. Since rules wrap the test stack, they are the perfect place to inject such logic. It might even be possible to inject the rule into the test code at compile time making the change possibly passive.
          Hide
          Benjamin R. Doerr added a comment -

          As a side. Would it be possible to have this feature for unit tests only where things you mentioned are not a problem?

          Show
          Benjamin R. Doerr added a comment - As a side. Would it be possible to have this feature for unit tests only where things you mentioned are not a problem?
          Hide
          Magno Machado Paulo added a comment -

          Couldn't grails use AOP to inject whatever behaviour it needs into the tests (DI, transaction, etc), without relying on a test runner?

          Show
          Magno Machado Paulo added a comment - Couldn't grails use AOP to inject whatever behaviour it needs into the tests (DI, transaction, etc), without relying on a test runner?
          Hide
          Graeme Rocher added a comment -

          This works in 2.3.0 master.

          It will result in a breaking change that will require changes to user code for integration tests.

          All integration tests that require dependency injection etc. now need to be annotated with

          @TestMixin(IntegrationTestMixin)
          

          Since we no longer use the special test runner to run tests.

          Show
          Graeme Rocher added a comment - This works in 2.3.0 master. It will result in a breaking change that will require changes to user code for integration tests. All integration tests that require dependency injection etc. now need to be annotated with @TestMixin(IntegrationTestMixin) Since we no longer use the special test runner to run tests.
          Hide
          Graeme Rocher added a comment -

          For Spock tests extending 'IntegrationSpec' also works

          Show
          Graeme Rocher added a comment - For Spock tests extending 'IntegrationSpec' also works

            People

            • Assignee:
              Graeme Rocher
              Reporter:
              Robert Fletcher
            • Votes:
              30 Vote for this issue
              Watchers:
              27 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Last Reviewed:

                Development