JUnit testcase passes with eclipse but fails with maven build

后端 未结 2 619
甜味超标
甜味超标 2021-01-20 22:38

I wrote a JUnit test case for JPA using spring. The testcase passes in eclips. But if I execute the same testcase using maven (mvn test) it fails.

My test case is :

相关标签:
2条回答
  • 2021-01-20 22:53

    It looks like you run in a Problem with the Java EE API package that contains only empty interfaces.

    Replace

    <dependency>
        <groupId>javaee</groupId>
        <artifactId>javaee-api</artifactId>
    </dependency>
    

    by:

        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
    

    More details can be found here.

    0 讨论(0)
  • 2021-01-20 22:54

    I have solved this problem. The problem was mainly because of the dependency

    <dependency> 
        <groupId>javaee</groupId> 
        <artifactId>javaee-api</artifactId> 
        <version>5</version> 
        <scope>provided</scope> 
    </dependency>
    

    Actually this dependency was required for EJB so I placed this in my parent pom (and also in my testcases pom). Since my test case's pom had a parent depedency, by default it will be inherited. If you add this dependency then u must have a java EE container to run the program. Testcase does not require Java EE container.

    Remove this dependency if you have the one in your pom file.

    Have a look on Problem running unit tests from maven (JPA related) for more detail.

    0 讨论(0)
提交回复
热议问题