java - Running JUnit tests with and without before/after hooks -
i have situation need able run suite of junit tests under 2 different "modes":
- with first mode, use
@before
,@after
annotations/methods used; but... - with second mode, not use these annotations/methods, run same
@test
methods
for example:
public class widgettest { @before void start() { // start work. } @after void stop() { // shutdown work. } @test public void testwidget() { // given/when/then, etc. } }
in "mode #1", want @before
, @after
methods (start()
, stop()
respectively) execute before/after testwidget()
. in "mode #2", only want testwidget()
method fire.
the best can come is:
public class widgettest { private boolean usehooks; // ctor, getter , setter 'usehooks'. @before void start() { if(usehooks) { // start work. } } @after void stop() { if(usehooks) { // shutdown work. } } @test public void testwidget() { // given/when/then, etc. } }
but presents additional problem: how inject usehooks
test suite? kind of hacky, , guess i'm hoping junit supports kind of use case out of box.
is there way accomplish this? if so, how?
check out @category
annotation
Comments
Post a Comment