@Test
@RunWith(GuiceInitializer.class) // also be able to specify this
globally for all my tests
class A {
@Inject
private Database db;
...
}
class GuiceInitializer {
@BeforeClass
public void initTestClass(Object testInstance) {
...
injector.injectInstance(testInstance);
}
}
Any thoughts?
Erik.
I don’t think there is any case where you cannot put the annotations in a parent class, or use several levels of inheritance. It’s more a matter of organization, I’d like to have a generic Guice testing framework and use the inheritance to group functions and my own annotations for each of my modules.
Why do you think @RunWith would be a headache for integration? Aren’t they all only detecting the @Test and then hand the execution to the test runner? In my example, you won’t pass a test runner to @RunWith, rather somekind of interceptor – so the IDE shouldn’t need to handle it.
Erik.
From:
testn...@googlegroups.com [mailto:testn...@googlegroups.com] On Behalf Of Cédric Beust ?
Sent: January-20-09 3:43 PM
To: testn...@googlegroups.com
Subject: Re: @RunWith annotation
The only benefit I can see is that it lets you extend a different class if you so desire, but I'm not really convinced it's really that useful.
Let me ask you this: can you think of scenarios where the annotations that you need cannot be put on the class you extend?
Besides, @RunWith is also a headache for integration since most IDE's will ignore it and they will therefore not make these symbols available to the plug-in...
--
C餲ic
I don't think there is any case where you cannot put the annotations in a parent class, or use several levels of inheritance. It's more a matter of organization, I'd like to have a generic Guice testing framework and use the inheritance to group functions and my own annotations for each of my modules.
Why do you think @RunWith would be a headache for integration? Aren't they all only detecting the @Test and then hand the execution to the test runner? In my example, you won't pass a test runner to @RunWith, rather somekind of interceptor – so the IDE shouldn't need to handle it.
So instead of a @RunWith maybe specifying the listeners and hooks with annotations would do the trick (I never use the suite.xml files)?
I haven’t found in the listeners something that would correspond to a @BeforeClass but if there is something equivalent, this might be a better way.
Something such as @Listeners(GuiceInitializer.class)
Erik.
From:
testn...@googlegroups.com [mailto:testn...@googlegroups.com] On Behalf Of Cédric Beust ?
Sent: January-20-09 4:11 PM
To: testn...@googlegroups.com
Subject: Re: @RunWith annotation
2009/1/20 Putrycz, Erik <Erik.P...@nrc-cnrc.gc.ca>
Why do you think @RunWith would be a headache for integration? Aren't they all only detecting the @Test and then hand the execution to the test runner? In my example, you won't pass a test runner to @RunWith, rather somekind of interceptor so the IDE shouldn't need to handle it.
The problem is that @RunWith is basically a way to substitute your own runner to whatever other is currently in place. IDE's typically use their own runner to keep track of progress, so you usually lose a lot of IDE functionality as soon as you use @RunWith in your tests.
The way I see it, JUnit wasn't designed with enough listening and hooking infrastructure in place, so they had to resort to @RunWith to give at least some flexibility to developers. "Our engine is a black box, but you can replace it completely".
Fixing this was one of my early goals with TestNG, which I achieved by providing not just more configuration annotations but also more listeners and hooks into the engine so that its behavior can be modified and overridden without compromising tooling.
--
C餲ic
So instead of a @RunWith maybe specifying the listeners and hooks with annotations would do the trick (I never use the suite.xml files)?
I think what Cedric meant is that if something such as @RunWith was
added, all the IDE plugins would need to "recognize" it whereas changes
in the test runner only are much easier for all the IDE plugin
maintainers.
> Is it possible to write a custom runner for TestNG that gives me full
> control over test execution like JUnit does? Last time I checked, I
> couldn't
> find a way to do this.
Could you detail what you need custom runner for?
I looked at the JUnit Runner API and it doesn't look too friendly. There
should be better ways to customize the test execution.
Erik.
I think what Cedric meant is that if something such as @RunWith was
> IDE runners don't have to be aware of @RunWith except that they need
> to
> recognize classes with this annotation as JUnit tests. JUnit will do
> the rest. Sorting and filtering tests should still work, unless the
> user-provider runner doesn't support it.
added, all the IDE plugins would need to "recognize" it whereas changes in the test runner only are much easier for all the IDE plugin
maintainers.
Could you detail what you need custom runner for?
> Is it possible to write a custom runner for TestNG that gives me full
> control over test execution like JUnit does? Last time I checked, I
> couldn't
> find a way to do this.
I looked at the JUnit Runner API and it doesn't look too friendly. There
should be better ways to customize the test execution.
Cédric Beust ♔ wrote:
>
> With @RunWith, developers writing runner classes now compete with IDE's
>
Just to make sure that we are on the same page: For IDEs that use JUnit in
the way it is intended to be used, @RunWith is totally transparent: IDE
calls JUnit calls @RunWith runner. As of JUnit 4.5, this should take you
pretty far. I'm wondering if it's still necessary to "abuse" JUnit to offer
good IDE integration, but I'm not an expert here.
From the standpoint of a framework developer, the good thing about @RunWith
is that it gives you a lot of flexibility. The bad thing is that it isn't
obvious how to write a fully conforming runner, and that you have to
reinvent the wheel even if you only need a slight variation of the standard
runner. That's why JUnit 4.5 has introduced an API that facilitates the
writing of runners that, to some extent, follow the JUnit model.
Cédric Beust ♔ wrote:
>
> I was going to ask just that to Peter: please explain what you are trying
> to do and let's see what we can do.
>
I'm writing my own test framework and would like to reuse TestNG's IDE and
build tool integration. Not sure if you consider this a valid use case. :-)
Anyway, @RunWith works pretty well for me, but I haven't found a way to
integrate with TestNG.
Cheers,
Peter
--
View this message in context: http://www.nabble.com/%40RunWith-annotation-tp21570801p21590053.html
Sent from the testng-dev mailing list archive at Nabble.com.
I'm writing my own test framework and would like to reuse TestNG's IDE and
Cédric Beust ♔ wrote:
>
> I was going to ask just that to Peter: please explain what you are trying
> to do and let's see what we can do.
>
build tool integration. Not sure if you consider this a valid use case. :-)
Anyway, @RunWith works pretty well for me, but I haven't found a way to
integrate with TestNG.
So what is specific about your test framework?
Erik.