Loading ...
Sorry, an error occurred while loading the content.

Re: [junit] junit-nested: TestRunner for non-static inner classes

Expand Messages
  • Esko Luontola
    As they say, great minds think alike. :) Some years ago I wrote a similar thing, even named it almost the same: https://github.com/orfjackal/nestedjunit If
    Message 1 of 4 , Aug 14, 2013
    • 0 Attachment
      As they say, great minds think alike. :) Some years ago I wrote a similar
      thing, even named it almost the same:
      https://github.com/orfjackal/nestedjunit If yours supports arbitrary depth,
      then that's more than nestedjunit does (it supports only max 2 levels of
      tests). Is the test isolation also the same?

      I got used to that style of organizing tests when learning TDD and writing
      tests with JDave. I've found 1-2 levels is nearly always enough, though I
      appreaciate the flexibility of arbitrary depth. For other JVM languages,
      and Java with lambda expressions, I've written an even more flexible
      testing framework: http://specsy.org/ You might like it, so have a look.
      (It requires the http://jumi.fi/ test runner, which is still lacking in
      tool support, so that's a negative side, for now.)


      On Wed, Aug 14, 2013 at 7:53 AM, Aaron V. <gruen0aermel@...> wrote:

      > **
      >
      >
      > I'm announcing the 1.0 release of junit-nested, a TestRunner that allows
      > test classes to contain non-static inner classes which also have test
      > methods. Inner test classes can be nested to arbitrary depth, and @Before
      > and @After methods and @Rules will be run at all levels--that is, tests in
      > inner classes will get the benefit of befores and afters in their parent
      > (and grandparent, etc) classes.
      >
      > Of course, whether or not you _should_ make use of nested tests I find is
      > a matter of debate, but nonetheless it's a useful tool to have at your
      > disposal (and rspec (ruby), Cedar (obj-c) and jasmine (javascript) all
      > promote nested test structures).
      >
      > Source code (and an example) is available
      > https://github.com/avh4/junit-nested and the jar is available on maven
      > central as net.avh4.test:junit-nested:1.0.1
      >
      > It is currently licensed under the EPL. If you have need of a different
      > license, please contact me.
      >
      > Also, if anyone with more knowledge of the internals of
      > BlockJUnit4ClassRunner can make any suggestions on improving my attempts to
      > extend it, I would appreciate the feedback.
      >
      > https://github.com/avh4/junit-nested/blob/master/src/main/java/net/avh4/test/junit/InnerRunner.java
      >
      > Cheers,
      > --Aaron V.
      >
      >


      [Non-text portions of this message have been removed]
    • Aaron VonderHaar
      Cool, I did take a look at specsy before I started Nested, but I didn t want to use anonymous classes for each test, and I m not quite ready to commit to JDK
      Message 2 of 4 , Aug 15, 2013
      • 0 Attachment
        Cool, I did take a look at specsy before I started Nested, but I didn't
        want to use anonymous classes for each test, and I'm not quite ready to
        commit to JDK 8 or scala/groovy yet.

        As for test isolation, currently each each inner class instance gets its
        own independent outer class instance, so everything should be completely
        isolated.


        On Wed, Aug 14, 2013 at 6:23 AM, Esko Luontola <esko.luontola@...>wrote:

        > **
        >
        >
        > As they say, great minds think alike. :) Some years ago I wrote a similar
        > thing, even named it almost the same:
        > https://github.com/orfjackal/nestedjunit If yours supports arbitrary
        > depth,
        > then that's more than nestedjunit does (it supports only max 2 levels of
        > tests). Is the test isolation also the same?
        >
        > I got used to that style of organizing tests when learning TDD and writing
        > tests with JDave. I've found 1-2 levels is nearly always enough, though I
        > appreaciate the flexibility of arbitrary depth. For other JVM languages,
        > and Java with lambda expressions, I've written an even more flexible
        > testing framework: http://specsy.org/ You might like it, so have a look.
        > (It requires the http://jumi.fi/ test runner, which is still lacking in
        > tool support, so that's a negative side, for now.)
        >
        > On Wed, Aug 14, 2013 at 7:53 AM, Aaron V. <gruen0aermel@...> wrote:
        >
        > > **
        >
        > >
        > >
        > > I'm announcing the 1.0 release of junit-nested, a TestRunner that allows
        > > test classes to contain non-static inner classes which also have test
        > > methods. Inner test classes can be nested to arbitrary depth, and @Before
        > > and @After methods and @Rules will be run at all levels--that is, tests
        > in
        > > inner classes will get the benefit of befores and afters in their parent
        > > (and grandparent, etc) classes.
        > >
        > > Of course, whether or not you _should_ make use of nested tests I find is
        > > a matter of debate, but nonetheless it's a useful tool to have at your
        > > disposal (and rspec (ruby), Cedar (obj-c) and jasmine (javascript) all
        > > promote nested test structures).
        > >
        > > Source code (and an example) is available
        > > https://github.com/avh4/junit-nested and the jar is available on maven
        > > central as net.avh4.test:junit-nested:1.0.1
        > >
        > > It is currently licensed under the EPL. If you have need of a different
        > > license, please contact me.
        > >
        > > Also, if anyone with more knowledge of the internals of
        > > BlockJUnit4ClassRunner can make any suggestions on improving my attempts
        > to
        > > extend it, I would appreciate the feedback.
        > >
        > >
        > https://github.com/avh4/junit-nested/blob/master/src/main/java/net/avh4/test/junit/InnerRunner.java
        > >
        > > Cheers,
        > > --Aaron V.
        > >
        > >
        >
        > [Non-text portions of this message have been removed]
        >
        >
        >



        --
        --Aaron V.
        [ http://github.com/avh4 ]


        [Non-text portions of this message have been removed]
      • Esko Luontola
        ... Yeah, that s understandable. JDK 8 is still at beta and changing the language can be a big change. In some projects I m using
        Message 3 of 4 , Aug 16, 2013
        • 0 Attachment
          Aaron VonderHaar wrote on 16.8.2013 5:05:
          > Cool, I did take a look at specsy before I started Nested, but I didn't
          > want to use anonymous classes for each test, and I'm not quite ready to
          > commit to JDK 8 or scala/groovy yet.

          Yeah, that's understandable. JDK 8 is still at beta and changing the
          language can be a big change.

          In some projects I'm using https://github.com/orfjackal/retrolambda to
          get lambda expressions on Java 7. I compile the source with JDK 8 and
          then use Retrolambda to convert the lambdas into regular anonymous
          clases, so that they will run on earlier JREs.

          > As for test isolation, currently each each inner class instance gets its
          > own independent outer class instance, so everything should be completely
          > isolated.

          Good. That's the way I like it and how JUnit does it. TestNG users may
          disagree. ;) For some reason not all understand it:
          http://stackoverflow.com/questions/1052577/why-must-junits-fixturesetup-be-static

          I have one idea that how to implement a shared instance for all test
          methods, without violating the default test isolation. The test class
          could take as constructor parameter an object, which the test runner
          will instantiate only once and pass the same instance to all test class
          instances. Then that injected object could be used to hold shared state
          (e.g. database connection) without having to use static fields.

          I'm planning to implement that in Specsy. Already now it should be
          possible to implement it at the level of one test class, but in the
          future I'll improve Jumi to support implementing that at the level of
          _all_ test classes in the suite. I'll make it so that only one Driver
          [1] instance (it corresponds JUnit's Runner class) is created and it
          will be used for all test classes. Also the Driver will receive an event
          when the suite is finished (for teardown of the shared state).

          [1] http://jumi.fi/api/jumi-api/fi/jumi/api/drivers/Driver.html

          --
          Esko Luontola
          www.orfjackal.net
        Your message has been successfully submitted and would be delivered to recipients shortly.