The latest Arquillian release (1.3.0) introduces an interesting new SPI that allow automatic generation of the deployment, ie. avoiding the need for an explicit @Deployment method.
We do a lot of testing against Atlassian products using our home grow Arquillian extension: Adaptavist / atlassian-arquillian-containers — Bitbucket
This new SPI intrigued me as the majority of our tests have the same very simple @Deployment method:
@Deployment public static Archive deployTests() { return ShrinkWrap.create(JavaArchive.class, "tests.jar"); }
but a few include other things. It'd be nice if all the simple cases could ditch the method entirely without affecting other cases.
So, I tried a very simple AutomaticDeployment:
public class DefaultDeployment implements AutomaticDeployment { @Override public DeploymentConfiguration generateDeploymentScenario(TestClass testClass) { return new DeploymentContentBuilder(ShrinkWrap.create(JavaArchive.class, "tests.jar")).get(); }
and add the fully qualified class name to this file: src/test/resources/META-INF/services/org.jboss.arquillian.container.test.spi.client.deployment.AutomaticDeployment
This works great for new test cases WITHOUT a @Deployment, but it clobbers any existing cases, complaining about Deployments with the same name '_DEFAULT_' clashing.
So, I extended this to check for the existence of a deployment method, and only generate one if the test case doesn't contain any:
public class DefaultDeployment implements AutomaticDeployment { @Override public DeploymentConfiguration generateDeploymentScenario(TestClass testClass) { if (hasDeploymentMethod(testClass)) { return null; } else { return createDefaultDeployment(); } } private boolean hasDeploymentMethod(TestClass testClass) { return testClass.getMethods(Deployment.class).length > 0; } private DeploymentConfiguration createDefaultDeployment() { return new DeploymentContentBuilder(ShrinkWrap.create(JavaArchive.class, "tests.jar")).get(); } }
Anyway, I hope this helps anyone getting started with this feature, as there doesn't appear to be much in the way of documentation or examples for it, and it took me a bit of digging in the Arquillian source to work out what I needed to do.
Comments