unit testing EJBs with Maven 2 and Glassfish 3

后端 未结 1 1975
说谎
说谎 2021-02-01 09:33

I\'ve been trying to set my application up so that I can unit test it\'s EJBs all day but I can\'t seem to get past what seems like a really simple problem.

I have a sta

相关标签:
1条回答
  • 2021-02-01 09:53

    (...) The standard recommended solution is to add the glassfish-embedded-all artifact as the first project dependency with test scope

    Indeed, you need an implementation like glassfish-embedded-all or glassfish-embedded-web if you're only using the web profile, which seems to be your case (I didn't know that the web profile was providing EJBContainer by the way).

    And to be precise, this artifact doesn't have to be the "first" dependency but it must be declared before the javaee-api artifact.

    So, is there a Maven repository that Nexus will be able to index to give me the glassfish-embedded-all artifact?

    I couldn't reproduce the issue with http://download.java.net/maven/glassfish/ but it appears that JBoss Nexus repository does have it (probably because they use it in Arquillian):

    <repository>
      <id>jboss-public-repository-group</id>
      <name>JBoss Public Maven Repository Group</name>
      <url>https://repository.jboss.org/nexus/content/groups/public</url>
    </repository>
    

    is this even the correct way to go about unit testing EJBs?

    Unit tests are typically done outside-container and in isolation (using a Mocking framework) so I wouldn't call that unit testing. But for integration/functional testing (in-container), the EJBContainer API is really great and perfectly fine.

    See also

    • TOTD #128: EJBContainer.createEJBContainer: Embedded EJB using GlassFish v3
    • Unit Testing EJBs and JPA with Embeddable GlassFish
    • Using the EJBContainer API with or without Maven (but with GlassFish v3)
    • Embedding EJB 3.1 Container Into Your Unit Tests - Boot Time: 5 Seconds
    • Unit Testing EJB 3.1 ...When 0.8 Seconds Are Too Long for a unit test example
    • The Arquillian project
    0 讨论(0)
提交回复
热议问题