Open RichardWarburton opened 10 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!
isSetupWith
doesn't work as I'd expect (ie like RSpec's before(:each)
) with nested describe
s.
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);
});
});
});
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.
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.
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.
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.
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.
is this being worked on? without nested describes lambda behave is just a nicer syntax but not does not really offer anything over junit.
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.