-
Notifications
You must be signed in to change notification settings - Fork 40.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration test fails when executing "mvn test" in a web project with JPA that has a schema.sql file #1454
Comments
Thanks for the detailed bug report. I've seen a couple of things that don't match 100% with your comments:
The problem's due to |
A workaround is to set |
@wilkinsona You are correct, when executing both tests from inside the IDE, I have also verified that However, I still experience that both tests passes if I remove the |
|
@dsyer Personally, I do not think that creating unique application contexts (nor Moreover, one would not expect the @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
public class ApplicationTests {
@Test
public void contextLoads() {
}
} |
You might not expect it, but since your test creates an application context it is going to initialize the database. Once you start doing heavy integration testing with a database you are going to have to deal with this problem (i.e. it's nothing really that we can help you with in Spring Boot). I recommend using profiles and being very careful not to create too many unique application contexts. Scrutinise each test that you end up with and see if it could be done with a shared application context, or one that is cheaper to start. |
You might also want to consider using a database migration tool such as Flyway. It's intelligent enough to only make a schema change if it hasn't already been applied to the database. |
The sample the reproduces the problem that this issue is about doesn't use If you do, then we've already investigated and offered three different solutions:
Unfortunately, re-opening the issue isn't going to change that. |
I've found the source of my problem, made sample to reproduce and created new issue: #7416 Problem is the same: schema.sql executes twice, but the source of the problem maybe different, so take a look to the new issue. |
I am facing this problem as of now. Is there any work around solutions ? |
@sunkuet02 this issue is four years old so I am not sure what exact problem you're facing. If you think you've found a bug in Spring Boot, please create a new issue with a small sample we can run ourselves to reproduce the problem. |
…ses CountryServiceTest are run with the command mvn test or mvn package. Ref: spring-projects/spring-boot#1454
When having a web-based project with a JPA based repository,
@WebAppConfiguration
integration test fails when executingmvn clean test
when there is aschema.sql
file present , despite settingspring.jpa.hibernate.ddl-auto=
as described in chapter 63.3 Initialize a database using Spring JDBC:Step by step:
mvn clean test
Expected result:
Actual result:
Comments:
schema.sql
file is deleted and thespring.jpa.hibernate.ddl-auto=
is removed from theapplication.properties
file@WebAppConfiguration
is removed from thePersonControllerTest
class.spring.jpa.hibernate.ddl-auto
tonone
does not prevent the test from failingEnvironment:
The text was updated successfully, but these errors were encountered: