RichardWarburton / lambda-behave

A modern testing and behavioural specification framework for Java 8
http://richardwarburton.github.io/lambda-behave/
MIT License
253 stars 52 forks source link

Support Nested Suite.describe() calls properly. #67

Open RichardWarburton opened 10 years ago

RichardWarburton commented 10 years ago

Previously it was thought this wasn't sensible given Junit runners, but discussion with potential users at the hackday suggested that they would be happy with nesting even if all it did was concatenate names.

BinaryTweedDeej commented 9 years ago

Hi,

I've been reading through some of the issues but I'm not sure if these have been addressed in 0.4, or flagged for fixing by the time 0.4 is done.

I've been doing some RSpec and would like feature parity with regards to nested describes (ie the outer describe is the class, the inner is each method) and contexts (ie context("when there are no existing users"...)

Is this something that's doable in 0.4-SNAPSHOT? Is there any way around the duplicate declarations of 'it' for each nesting of describe?

Thanks, and I really hope this library continues to develop. Sure beats any other way of writing Java tests!

BinaryTweedDeej commented 9 years ago

isSetupWith doesn't work as I'd expect (ie like RSpec's before(:each)) with nested describes.

The following code will never throw an exception:

describe("My method", outer -> {
   outer.isSetupWith(() -> { throw new RuntimeException("BANG") });

   describe("when the state of the world is X", it -> {
      it.should("do a thing", expect -> {
         expect.that(true).is(true);
      });
   });
});
RichardWarburton commented 9 years ago

Thanks. I would like to support nested describe statements - its completely reasonable and desirable thing. Unfortunately since we're currently using Junit to run tests its a bit hard to say what nested describes should correspond to. Should it be:

a. Suites, potentially nested within other suites? b. Concatenated names.

I'd love to hear your feedback. At the moment nested describe statements aren't supported at all.

Writtscher commented 9 years ago

Would be a great enhacement! In my opinion it would be enough to concatenate the names. I don't see any reason to nest suites unless each suite could provide the possibility to set up or clean up tests (like mocha where each describe can have it's own before/afterEach.

BinaryTweedDeej commented 9 years ago

Concatenated names would certainly be better. I'm not sure of the implications of nested suites? It'd be intuitive if isSetupWith from an outer describe applied to inner ones too.

christophsturm commented 9 years ago

I think nested describes should just work like junit's Enclosed runner. (@RunWith(Enclosed.class)) this way the tests show up nicely in idea. also nested describes should definately call the outer setup methods.

chrislwade commented 9 years ago

What about using HierarchicalContextRunner? It seems to handle multi-level @Before and @After methods in the test suites I've written with it.

When I realized I couldn't use nested describe, like I could with RSpec, I found this issue and looked into Enclosed but found that it doesn't appear to support in more than one layer of nesting. I ended up using HierarchicalContextRunner alone for now as the nested setup/teardown is more useful for the majority of the tests I'm writing at the moment.

Hopefully I'll find the time to integrate JUnitSuiteRunner with HierarchicalContextRunner and submit a PR but for now I leave it as a thought for others.

christophsturm commented 9 years ago

is this being worked on? without nested describes lambda behave is just a nicer syntax but not does not really offer anything over junit.