in Education by
This is a bit of an odd question, but it has been bothering me for a few months now. I have built a JPA-based web application using Wicket + Hibernate (built with Maven), and want to test the DAO layer directly. I created a specific src/test/resources/META-INF/persistence.xml file that I used for testing, but have been running into conflicts with WTP and the like. To get around these issues, I created a separate test project where the unit tests live. Is there a better way to manage unit tests for a JPA project without having duels between persistence files? Addendum: Would other test frameworks (TestNG, for example) make this any easier? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You may want to try mockito. The test works like this: You use mockito to "implement" EntityManager. Instead of the real code, you use the methods of mockito to say "if the application calls getReference(), then return this object". In the background, mockito will create a proxy instance which intercepts the Java method calls and returns the values which you specify. Calls to other methods will return null. Mocking things like createQuery() works the same way but you first need to create a mockup of Query and then use the same approach as in getReference() (return the query mockup). Since you don't use a real EM, you don't need a real persistence.xml. A much more simple solution would be if you could set some property to change the name of the persistence.xml file but I don't think that this is possible. Some other links that may help: How to configure JPA for testing in Maven Suggest a JPA Unit test framework

Related questions

0 votes
    What are some of the best practices in test automation?...
asked Jul 10, 2021 in Technology by JackTerrance
0 votes
    I'm writing some Java code that uses a FileReader to load data from a few input files. I'm using ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 9, 2022 in Education by JackTerrance
0 votes
    I'm writing some Java code that uses a FileReader to load data from a few input files. I'm using ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 8, 2022 in Education by JackTerrance
0 votes
    I'm writing some Java code that uses a FileReader to load data from a few input files. I'm using ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 7, 2022 in Education by JackTerrance
0 votes
    I'm writing some Java code that uses a FileReader to load data from a few input files. I'm using ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 6, 2022 in Education by JackTerrance
0 votes
    I've worked a lot with Pentaho PDI so some obvious things jump out at me. I'll call Connection ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    Some 4 years back, I followed this MSDN article for DateTime usage best practices for building a .Net ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    Some 4 years back, I followed this MSDN article for DateTime usage best practices for building a .Net ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    Traditionalist argue that stored procedures provide better security than if you use a Object Relational Mapping (ORM) ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    What are some best practices you should follow while using ServiceNow?...
asked May 25, 2021 in Technology by JackTerrance
0 votes
    Mention a few design and development best practices for Informatica....
asked Mar 27, 2021 in Technology by JackTerrance
0 votes
    What Are The Best Practices For Amazon Ec2 ?...
asked Mar 12, 2021 in Technology by JackTerrance
0 votes
    What Are The Security Best Practices For Amazon Ec2 ?...
asked Mar 12, 2021 in Technology by JackTerrance
0 votes
    What are the best practices to be followed while designing a secure RESTful web service?...
asked Nov 7, 2020 in Technology by JackTerrance
0 votes
    What are the best practices for caching in RESTful?...
asked Nov 7, 2020 in Technology by JackTerrance
...