我正在使用Arquillian和使用TestNG的嵌入式glassfish 3.1.2.2编写集成测试.我希望能够并行运行这些测试,对于这种情况,我需要动态配置glassfish端口和数据库名称(我们已经有了这个设置,我想重
我目前解决它的hacky方法是覆盖arquillian的beforeSuite方法,但是这个方法被调用两次 – 在测试启动时然后在容器中(因此我可怜的静态标志).其次,这个解决方案不适用于基于JUnit的测试,因为在套件之前无法拦截arquillian:
public class FullContainerIT extends Arquillian { private static boolean dbInitialized; //@RunAsClient <-supported by @Test only @Override @BeforeSuite(groups = "arquillian", inheritGroups = true) public void arquillianBeforeSuite() throws Exception { if (dbInitialized == false) { initializeDb(); dbInitialized = true; } super.arquillianBeforeSuite(); } }
我有一些想法:
@BeforeSuite @RunAsClient似乎是我需要的,但@RunAsClient仅支持@Test;
我在Arquillian JavaDocs看过org.jboss.arquillian.container.spi.event.container.BeforeStart事件,但我不知道如何听Arquillian事件;
我已经看到有可能让@Deployment创建一个ShrinkWrap Descriptor,但这些不支持Glassfish资源.
package com.example.extenstion; public class AutoDiscoverInstanceExtension implements org.jboss.arquillian.core.spi.LoadableExtension { @Override public void register(ExtensionBuilder builder) { builder.observer(LoadContainerConfiguration.class); } } package com.example.extenstion; public class LoadContainerConfiguration { public void registerInstance(@Observes ContainerRegistry, ServiceLoader serviceLoader) { //Do the necessary setup here String filteredFilename = doTheFiltering(); //Get the container defined in arquillian.xml and modify it //"default" is the container's qualifier Container definition = registry.getContainer("default"); definition.getContainerConfiguration() .property("resourcesXml", filteredFilename); } }
您还需要通过创建文件来配置SPI扩展
META-INF /服务/ org.jboss.arquillian.core.spi.LoadableExtension
这个内容:
com.example.extenstion.AutoDiscoverInstanceExtension