Q: Entities in src/test/java are not recognized As part of my tests I am creating a DAO that its sole purpose is in the tests. When attempting to run the unit test I am getting the following error: 
java.lang.IllegalArgumentException: Unknown entity:

It seems that when the entities reside in the src/test/java folder they don't get picked up. When moving the entity to src/main/java everything is working fine. Problem is that this DAO is solely for tests and I really don't want to put it in main. Is there a way to resolve this?

A: [If you are using JPA] You need to have a separate persistent unit(I would advice to have a separate persistence.xml in the test resources) for the test classes and need to mention all the actual ORM entities in the persistence.xml in class tag.
For instance, the strategy I followed, I created a TestUtility and in that I am injecting the persistent unit using CDI injection
private static final String PERSISTENCE_UNIT_NAME = "persistence-unit-test";
and building my entityManager:
public static EntityManager getEntityManager() {
    if (entityManager == null) {
        final EntityManagerFactory factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
        entityManager = factory.createEntityManager();
    }
    return entityManager;
}

