You must use framework arquillian from jboss itself http://www.mastertheboss.com/jboss-frameworks/arquillian/arquillian-tutorial.
What this framework does is this: in the background the instance of jboss is created. Everything is deployed there so you can then run your ejb's or servlets on that "background" container.
It is not easy to configure it, so I would recommend you to start with Jboss Tools for eclipse. Code looks then like this:
@Deployment
public static Archive<?> createTestArchive() {
return ShrinkWrap.create(WebArchive.class, "test-demo.war")
.addAsResource("META-INF/persistence.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
I do not favor this approach, it's really a separate deployment, you need to understand fully the structure of WAR and EJB packages and all other details.
It's really better, that you your EJB's , JPAs and Servlet beans are just light wrappers around normal java classes (POJO's), where the real logic resides. Then you can use plain unit tests to test those.