Re: [junit] junit-nested: TestRunner for non-static inner classes
- Aaron VonderHaar wrote on 16.8.2013 5:05:
> Cool, I did take a look at specsy before I started Nested, but I didn'tYeah, that's understandable. JDK 8 is still at beta and changing the
> want to use anonymous classes for each test, and I'm not quite ready to
> commit to JDK 8 or scala/groovy yet.
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 itsGood. That's the way I like it and how JUnit does it. TestNG users may
> own independent outer class instance, so everything should be completely
disagree. ;) For some reason not all understand it:
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
 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).