spring-testing | Small demo project intended to show | Application Framework library
kandi X-RAY | spring-testing Summary
kandi X-RAY | spring-testing Summary
This is a simplistic demo project intended to show how some Spring features can be used to improve your Spring test suite. The project has been used as demo during conference sessions. During SpringOne 2GX 2013 the session was recorded and you can watch it on YouTube. Below you will find references to where the concepts in the presentation have been used in the source code.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Jackson entity manager factory bean .
- Compares two account numbers .
- Returns a list of all accounts .
- Create data source for database .
- Creates a new account
- Configures the HttpSecurityPolicy with authorization policies .
- String representation of AccountEntity
- Returns a list of all account numbers .
- Gets the amount of amount in minutes .
- Entry point for the Spring Boot application .
spring-testing Key Features
spring-testing Examples and Code Snippets
Community Discussions
Trending Discussions on spring-testing
QUESTION
I have a Spring Boot project and I want to test some queries. I want to insert a predefined set of data and execute the Repository query to check the result is the desired one.
To do this I'm using in-memory H2 DB and the problem (I think) is not there, everything related with DB is ok. The main problem is I can't mock properly the EntityManager
field in repository and the query is always null.
My repository is like this:
...ANSWER
Answered 2021-Dec-22 at 15:41Since you're using an h2 in-memory database to run tests, and you want to actually use that database in your tests, you shouldn't really be mocking anything.
Your mocking doesn't work because the MyRepositoryImpl is typically initialized by Spring, and that process is much more complicated than plugging in an EntityManager.
I think what you want to do is more like what's described here https://www.baeldung.com/spring-testing-separate-data-source
So you would have a src/test/resources/application.properties file that overrides the datasource properties. Then you just @Autowired your repository into your test class like normal.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install spring-testing
You can use spring-testing like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the spring-testing component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page