JUnit Run Configuration: executeBefore?

Hi all,

Not sure whether this "request" makes sense, thus I'd like to first
"discuss" it here.
What I would like to do is to, within a JUnit-run configuration, have
something execute before the tests run (and probably after that) - I
know I can do this with a JUnit-suite or in each testcase but I don't
want to put this into the tests as this "before" method is
resource-intensive. On the other hand I don't want to create a Suite as
they always get out-of-sync (e.g. tests missing) and I prefer IDEA's
JUnit run-configurations (e.g. execute all in package/module/project
etc.) - they don't need to be maintained.
Long talk, short request: Is it possible to have beforeAllTests and
maybe afterAllTests) methods/code or, if not, would it make sense to add
such a feature?

kind regards,

Messi

5 comments
Comment actions Permalink

There's an answer, but you may not like it. Move to either JUnit 4 or TestNG, both of which support that feature. JUnit4 is supported by IDEA 6.0, and TestNG support is available via plugin.

--Dave Griffith

0
Comment actions Permalink

Hello Dave,

Thanks for your quick reply, I didn't have time yet to look much into
JUnit 4, I'm doing this now (much too late, I admit ;) ), moving to
JUnit 4 may be an option, I'll have to look into it...
Am I correct you mean @BeforeClass and @AfterClass annotations? These
make it simpler but still require to call the "setup" method in each
test-collection (manually).

kind regards,

Messi

Dave Griffith wrote:

There's an answer, but you may not like it. Move to either JUnit 4 or TestNG, both of which support that feature. JUnit4 is supported by IDEA 6.0, and TestNG support is available via plugin.

--Dave Griffith

0
Comment actions Permalink

Actually I meant @BeforeSuite/@AfterSuite, but those are specific to TestNG. I mistakenly remembered something similar in JUnit 4, but no joy. Sorry about that.

--Dave Griffith

0
Comment actions Permalink

I found this site too, didn't have time to post it here... however, this
approach requires to still maintain suites manually, which I don't like
(I rather execute "all in package" "all in module" etc., that's why I
thought this would need to be added to IDEA) - same for TestNG, however,
but it seems a bit simpler to do this (as I can define an XML-suite and
include (all tests in) package xyz, not recursively although).

Finally, because of what I wrote above and in previous postings, I still
thiunk this would make a nice IDEA-addition, sth. like "execute in
Context", not "very important" though, not sure how many users would
need it.

kind regards,

Messi

David Saff wrote:

JUnit 4 does indeed have a similar capability. Check out:

http://shareandenjoy.saff.net/2006/08/beforeclass-and-afterclass-on-suites.html

0

Please sign in to leave a comment.