Reputation: 1336
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
Upvotes: 6
Views: 8472
Reputation: 4065
You can use the existing EAR/WAR/JAR
of your app because creating EAR
with ShrinkWrap
would be annoying in some complex cases (many dependencies etc).
The @Deployment
method should embed the test WAR into the EAR and add a module element into existing application.xml
before returning the archive to Arquillian runtime.
A @Deployment
method example:
...
@Deployment
public static Archive<?> createDeploymentPackage() throws IOException {
final String testWarName = "test.war";
final EnterpriseArchive ear = ShrinkWrap.createFromZipFile(
EnterpriseArchive.class, new File("target/myApp.ear"));
addTestWar(ear, myClassTest.class, testWarName);
...
Arquillian EJB-JAR/EAR testing examples
Arquillian EJB-JAR/EAR testing examples/Github
SO: How to add test classes to an imported ear file and run server side with arquillian?
Upvotes: 0
Reputation: 803
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")
Upvotes: 17