Giter VIP home page Giter VIP logo

Comments (11)

sagar-rout avatar sagar-rout commented on May 23, 2024 1

Generally I don't prefer using H2 because it may give you wrong impression how it will behave with real database. Using real database with docker will give you close impression of database

from generator-springboot.

sagar-rout avatar sagar-rout commented on May 23, 2024

Hi, I can work on it.

I believe we want to test repo IT using DataJpaTest, Is there any default convention you want to configure like

  • Using H2 or HSQL db

from generator-springboot.

rajadilipkolli avatar rajadilipkolli commented on May 23, 2024

Hi @sagar-rout ,

Since we already have H2 in the dependency, spring boot will automatically pick it up.

If you got struck anywhere, please ping us we will help you. Assigned ticket to you

from generator-springboot.

sagar-rout avatar sagar-rout commented on May 23, 2024

yeah, I know that spring will pick up H2 from classpath and do you want me to turn off this setting by using
@ AutoConfigureTestDatabase

from generator-springboot.

rajadilipkolli avatar rajadilipkolli commented on May 23, 2024

Ideally, if we want to test only repository layer then we need to connect to real database (postgres, MySQL, etc...)which we are using in our application. But here as we have integration tests that connects to real database then it will become duplicate effort. Hence for Repository tests we can go with H2.

@sivaprasadreddy , please provide your thoughts.

from generator-springboot.

sivaprasadreddy avatar sivaprasadreddy commented on May 23, 2024

I would definitely prefer to use the same type of database for testing which we use for production.
We don't need to write tests for the repository methods provided by framework itself(findAll(), findById(), etc).
If there are integration tests that covers your custom methods then we may not have to write repository test as it is going to be redundant.

from generator-springboot.

sagar-rout avatar sagar-rout commented on May 23, 2024

so, I would say having a skeleton for repo would be more than enough and I can mark the H2 disable which may force the user to use the db.

from generator-springboot.

sivaprasadreddy avatar sivaprasadreddy commented on May 23, 2024

Currently H2 config/code is added by default. I think we can make it one of the options like MySQL, PostgreSQL, etc and add H2 related code only when H2 is selected. With Spring Boot version 3.1.0+ support for Testcontainers, we hardly need H2.

from generator-springboot.

rajadilipkolli avatar rajadilipkolli commented on May 23, 2024

Hi @sagar-rout , when you are working on PR, can you please move the ApplicationIntegrationTest to repository layer like in this PR and rename it.

As it becomes slice testing it will not load beans from other layer thus reducing the executing time. This also sets up infrastructure for @DataJpaTest

cc : @sivaprasadreddy

from generator-springboot.

sivaprasadreddy avatar sivaprasadreddy commented on May 23, 2024

Hi @rajadilipkolli @sagar-rout
I think we have mixed up 2 different things in this issue.
One is generating tests for Jpa Repositories and two is adding schema validation test.

Regarding schema validation test: We already have ApplicationIntegrationTest which is an integration test that will verify whether the application can be started properly or not provided the required services via Testcontainers. It is also configured to perform schema validation as well. So schema validation is already taken care of.

Regarding generation of tests for Jpa Repository: Currently we are not adding any custom methods to the generated JpaRepositories. I believe we shouldn't need to test the methods inherited from framework like save(), findAll() etc. So, generating tests might not be useful.

I will create a separate issue to make H2 database as one of the option instead of adding it by default.

So, I am closing this issue for now. If you disagree, please feel free to re-open this issue. We can discuss further.

from generator-springboot.

rajadilipkolli avatar rajadilipkolli commented on May 23, 2024

Hi @sivaprasadreddy , I will work on the PR, to provide infra for @DataJPATest, then we can decide if we should reopen this issue.

Regarding Schema validation Test, we are loading the whole application context, which is counterproductive, as the same can be achieved with @DataJpaTest quickly. So, want to pursue it by combining both.

Background to this issue, I have an application which uses graphql, verifies schema and perform some initial steps as a result the time taken to execute SchemaValidation test is up to 30sec, when I have modified the same to use @DataJpaTest it was completed in 10 sec.

from generator-springboot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.