I am using arquillian for unit test. I am creating deployment jar using shrinkWrap. But for that I need to add all the packages which are used in my project, which are a lot in number.
following is my test file
@RunWith(Arquillian.class)
public class GreeterTest {
@Deployment
public static JavaArchive createDeployment() throws NamingException {
return ShrinkWrap.create(JavaArchive.class, "test.jar")
.addPackage(ABC.class.getPackage())
.addPackage(EFG.class.getPackage())
.addPackage(HIJ.class.getPackage())
.addPackage(KLM.class.getPackage())
.addPackage(NOP.class.getPackage())
.addPackage(QRS.class.getPackage())
.addPackage(TUV.class.getPackage())
.addPackage(XYZ.class.getPackage())
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
@Inject
ABC abc;
@Inject
EFG efg;
@Inject
HIJ hij;
@Inject
KLM klm;
@Inject
NOP nop;
@Test
public void shouldBeAbleToInjectEJBAndInvoke() throws Exception {
abc.getDetail();
}
}
You can see .addPackage(). there are hundreds of packages in my project. Obvious code size will be increasing enormously
Is there any other way for this? Or I must be making some big mistake
I'd recommend you to use string representation of package path: "com.root.core" etc. And there are methods:
addPackage(String pack)
addPackages(boolean recursive, String... packages)
The latest is more appropriate for you I guess as it provides you a possibility to add packages recursively and thus you avoid repeatedly including every package. For instance:
.addPackages(true, "com.root")