Sometimes I need to write some functionality that runs before each test and is aware of which test method it runs (JUnit4). So I'm using TestWatchman for that, but @Inject'able attributes are null whet "public void starting(FrameworkMethod method)" method is invoked.
Would it be possible to adjust Aruillian to do injection before junit runs @Rule? Or is there another way to write piece of code that is fired before each test and is aware of test method?
Currently I'm writing @Rule that starts contexts (like mock of ViewScopedContext) if test method is marked with appropriate annotations.
You should be able to do that using the Arquillian SPI's.. They are a bit under documented at the moment, but work in progress: https://github.com/aslakknutsen/arquillian.github.com/blob/spi_guide/guides/getting_started_spi.textile
Arquillian has two sides to it, the Client side and the Container side.
You can use the AuxiliaryArchiveAppender to create a Container v of your self, which register a RemoteLoadableExtension (same as LoadableExtension but used in Container)
See e.g. the CDI TestEnricher
Aslak, I've encountered problems (BoundConversationContext class not found from arquillian-service). Well it looks like when i'm using "Servlet 3.0" protocol then all libraries generated by AuxiliaryArchiveAppender are packaged into WAR, but if I don't specify that protocol then those jars are packaged into "arquillian-service.jar" but that jar doesn't have "Dependencies:org.jboss.weld.core" and looking at the code I think that there is no way currently to merge dependencies of extension generated archives into that "arquillian-service.jar".
Other thing is that even with "Servlet 3.0" protocol I can't get the BoundConversationContext injected (it's null). BTW. which Inject annotation should I use from javax.inject or from arquillian?
I've already solved that problem. I was trying to inject (using javax.enterprise.inject.Instance) BoundConversationContext into class that is registered by remote extension as observer. Right now I'm injecting BeanManager and retrieve ConversationContext like that:
private <T extends Context> T getContext(Class<T> contextClass)
final BeanManager beanManager = beanManagerInstance.get();
@SuppressWarnings("unchecked") final Bean<T> bean = (Bean<T>) beanManager.getBeans(contextClass).iterator().next();
private BoundConversationContext getConversationContext()
And this works. So extension works fine for conversation. Now I'm fighting ViewScopedContext.
I've implemented the extension for this. It supports starting/stopping Conversation and View contexts for each test. Look at "test" module for usage. Currently it's bound tightly with Weld due to BoundConversationContext usage.
I've faces strange problem. I've annotated MockViewScopedContext as ApplicationScoped but when I tried to inject it into MockViewScopedCDIExtension it was a different instance then the one obtained later from BeanManager inside MockContextsManager.startContexts. Any idea why?